@@ -297,12 +297,14 @@ var (
297
297
// API settings
298
298
API = struct {
299
299
EnableSwagger bool
300
+ SwaggerURL string
300
301
MaxResponseItems int
301
302
DefaultPagingNum int
302
303
DefaultGitTreesPerPage int
303
304
DefaultMaxBlobSize int64
304
305
}{
305
306
EnableSwagger : true ,
307
+ SwaggerURL : "" ,
306
308
MaxResponseItems : 50 ,
307
309
DefaultPagingNum : 30 ,
308
310
DefaultGitTreesPerPage : 1000 ,
@@ -581,17 +583,17 @@ func NewContext() {
581
583
AppURL = strings .TrimRight (AppURL , "/" ) + "/"
582
584
583
585
// Check if has app suburl.
584
- url , err := url .Parse (AppURL )
586
+ appURL , err := url .Parse (AppURL )
585
587
if err != nil {
586
588
log .Fatal ("Invalid ROOT_URL '%s': %s" , AppURL , err )
587
589
}
588
590
// Suburl should start with '/' and end without '/', such as '/{subpath}'.
589
591
// This value is empty if site does not have sub-url.
590
- AppSubURL = strings .TrimSuffix (url .Path , "/" )
592
+ AppSubURL = strings .TrimSuffix (appURL .Path , "/" )
591
593
AppSubURLDepth = strings .Count (AppSubURL , "/" )
592
594
// Check if Domain differs from AppURL domain than update it to AppURL's domain
593
595
// TODO: Can be replaced with url.Hostname() when minimal GoLang version is 1.8
594
- urlHostname := strings .SplitN (url .Host , ":" , 2 )[0 ]
596
+ urlHostname := strings .SplitN (appURL .Host , ":" , 2 )[0 ]
595
597
if urlHostname != Domain && net .ParseIP (urlHostname ) == nil {
596
598
Domain = urlHostname
597
599
}
@@ -900,6 +902,10 @@ func NewContext() {
900
902
log .Fatal ("Failed to map Metrics settings: %v" , err )
901
903
}
902
904
905
+ u := * appURL
906
+ u .Path = path .Join (u .Path , "api" , "swagger" )
907
+ API .SwaggerURL = u .String ()
908
+
903
909
newCron ()
904
910
newGit ()
905
911
0 commit comments