mirror of
https://github.com/hrfee/jfa-go.git
synced 2024-12-22 17:10:10 +00:00
serve on / and URL base for easy proxying
This commit is contained in:
parent
81fb0fc69f
commit
f72def0399
80
main.go
80
main.go
@ -569,7 +569,7 @@ func start(asDaemon, firstCall bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
cssHeader = app.loadCSSHeader()
|
cssHeader = app.loadCSSHeader()
|
||||||
|
// workaround for potentially broken windows mime types
|
||||||
mime.AddExtensionType(".js", "application/javascript")
|
mime.AddExtensionType(".js", "application/javascript")
|
||||||
|
|
||||||
app.info.Println("Loading routes")
|
app.info.Println("Loading routes")
|
||||||
@ -583,7 +583,13 @@ func start(asDaemon, firstCall bool) {
|
|||||||
setGinLogger(router, debugMode)
|
setGinLogger(router, debugMode)
|
||||||
|
|
||||||
router.Use(gin.Recovery())
|
router.Use(gin.Recovery())
|
||||||
router.Use(static.Serve("/", static.LocalFile(filepath.Join(app.localPath, "web"), false)))
|
routePrefixes := []string{app.URLBase}
|
||||||
|
if app.URLBase != "" {
|
||||||
|
routePrefixes = append(routePrefixes, "")
|
||||||
|
}
|
||||||
|
for _, p := range routePrefixes {
|
||||||
|
router.Use(static.Serve(p+"/", static.LocalFile(filepath.Join(app.localPath, "web"), false)))
|
||||||
|
}
|
||||||
app.loadHTML(router)
|
app.loadHTML(router)
|
||||||
router.NoRoute(app.NoRouteHandler)
|
router.NoRoute(app.NoRouteHandler)
|
||||||
if debugMode {
|
if debugMode {
|
||||||
@ -592,42 +598,48 @@ func start(asDaemon, firstCall bool) {
|
|||||||
}
|
}
|
||||||
router.GET("/lang/:page", app.GetLanguages)
|
router.GET("/lang/:page", app.GetLanguages)
|
||||||
if !firstRun {
|
if !firstRun {
|
||||||
router.GET("/", app.AdminPage)
|
for _, p := range routePrefixes {
|
||||||
router.GET("/accounts", app.AdminPage)
|
router.GET(p+"/", app.AdminPage)
|
||||||
router.GET("/settings", app.AdminPage)
|
router.GET(p+"/accounts", app.AdminPage)
|
||||||
router.GET("/lang/:page/:file", app.ServeLang)
|
router.GET(p+"/settings", app.AdminPage)
|
||||||
router.GET("/token/login", app.getTokenLogin)
|
router.GET(p+"/lang/:page/:file", app.ServeLang)
|
||||||
router.GET("/token/refresh", app.getTokenRefresh)
|
router.GET(p+"/token/login", app.getTokenLogin)
|
||||||
router.POST("/newUser", app.NewUser)
|
router.GET(p+"/token/refresh", app.getTokenRefresh)
|
||||||
router.Use(static.Serve("/invite/", static.LocalFile(filepath.Join(app.localPath, "web"), false)))
|
router.POST(p+"/newUser", app.NewUser)
|
||||||
router.GET("/invite/:invCode", app.InviteProxy)
|
router.Use(static.Serve(p+"/invite/", static.LocalFile(filepath.Join(app.localPath, "web"), false)))
|
||||||
|
router.GET(p+"/invite/:invCode", app.InviteProxy)
|
||||||
|
}
|
||||||
if *SWAGGER {
|
if *SWAGGER {
|
||||||
app.info.Print(aurora.Magenta("\n\nWARNING: Swagger should not be used on a public instance.\n\n"))
|
app.info.Print(aurora.Magenta("\n\nWARNING: Swagger should not be used on a public instance.\n\n"))
|
||||||
router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
for _, p := range routePrefixes {
|
||||||
|
router.GET(p+"/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
api := router.Group("/", app.webAuth())
|
api := router.Group("/", app.webAuth())
|
||||||
router.POST("/logout", app.Logout)
|
for _, p := range routePrefixes {
|
||||||
api.DELETE("/users", app.DeleteUser)
|
router.POST(p+"/logout", app.Logout)
|
||||||
api.GET("/users", app.GetUsers)
|
api.DELETE(p+"/users", app.DeleteUser)
|
||||||
api.POST("/users", app.NewUserAdmin)
|
api.GET(p+"/users", app.GetUsers)
|
||||||
api.POST("/invites", app.GenerateInvite)
|
api.POST(p+"/users", app.NewUserAdmin)
|
||||||
api.GET("/invites", app.GetInvites)
|
api.POST(p+"/invites", app.GenerateInvite)
|
||||||
api.DELETE("/invites", app.DeleteInvite)
|
api.GET(p+"/invites", app.GetInvites)
|
||||||
api.POST("/invites/profile", app.SetProfile)
|
api.DELETE(p+"/invites", app.DeleteInvite)
|
||||||
api.GET("/profiles", app.GetProfiles)
|
api.POST(p+"/invites/profile", app.SetProfile)
|
||||||
api.POST("/profiles/default", app.SetDefaultProfile)
|
api.GET(p+"/profiles", app.GetProfiles)
|
||||||
api.POST("/profiles", app.CreateProfile)
|
api.POST(p+"/profiles/default", app.SetDefaultProfile)
|
||||||
api.DELETE("/profiles", app.DeleteProfile)
|
api.POST(p+"/profiles", app.CreateProfile)
|
||||||
api.POST("/invites/notify", app.SetNotify)
|
api.DELETE(p+"/profiles", app.DeleteProfile)
|
||||||
api.POST("/users/emails", app.ModifyEmails)
|
api.POST(p+"/invites/notify", app.SetNotify)
|
||||||
// api.POST("/setDefaults", app.SetDefaults)
|
api.POST(p+"/users/emails", app.ModifyEmails)
|
||||||
api.POST("/users/settings", app.ApplySettings)
|
// api.POST(p + "/setDefaults", app.SetDefaults)
|
||||||
api.GET("/config", app.GetConfig)
|
api.POST(p+"/users/settings", app.ApplySettings)
|
||||||
api.POST("/config", app.ModifyConfig)
|
api.GET(p+"/config", app.GetConfig)
|
||||||
api.POST("/restart", app.restart)
|
api.POST(p+"/config", app.ModifyConfig)
|
||||||
if app.config.Section("ombi").Key("enabled").MustBool(false) {
|
api.POST(p+"/restart", app.restart)
|
||||||
api.GET("/ombi/users", app.OmbiUsers)
|
if app.config.Section("ombi").Key("enabled").MustBool(false) {
|
||||||
api.POST("/ombi/defaults", app.SetOmbiDefaults)
|
api.GET(p+"/ombi/users", app.OmbiUsers)
|
||||||
|
api.POST(p+"/ombi/defaults", app.SetOmbiDefaults)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
app.info.Printf("Starting router @ %s", address)
|
app.info.Printf("Starting router @ %s", address)
|
||||||
} else {
|
} else {
|
||||||
|
11
views.go
11
views.go
@ -25,6 +25,13 @@ func (app *appContext) loadCSSHeader() string {
|
|||||||
return h
|
return h
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (app *appContext) getURLBase(gc *gin.Context) string {
|
||||||
|
if strings.HasPrefix(gc.Request.URL.String(), app.URLBase) {
|
||||||
|
return app.URLBase
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
func gcHTML(gc *gin.Context, code int, file string, templ gin.H) {
|
func gcHTML(gc *gin.Context, code int, file string, templ gin.H) {
|
||||||
gc.Header("Cache-Control", "no-cache")
|
gc.Header("Cache-Control", "no-cache")
|
||||||
gc.HTML(code, file, templ)
|
gc.HTML(code, file, templ)
|
||||||
@ -57,7 +64,7 @@ func (app *appContext) AdminPage(gc *gin.Context) {
|
|||||||
notificationsEnabled, _ := app.config.Section("notifications").Key("enabled").Bool()
|
notificationsEnabled, _ := app.config.Section("notifications").Key("enabled").Bool()
|
||||||
ombiEnabled := app.config.Section("ombi").Key("enabled").MustBool(false)
|
ombiEnabled := app.config.Section("ombi").Key("enabled").MustBool(false)
|
||||||
gcHTML(gc, http.StatusOK, "admin.html", gin.H{
|
gcHTML(gc, http.StatusOK, "admin.html", gin.H{
|
||||||
"urlBase": app.URLBase,
|
"urlBase": app.getURLBase(gc),
|
||||||
"cssClass": app.cssClass,
|
"cssClass": app.cssClass,
|
||||||
"contactMessage": "",
|
"contactMessage": "",
|
||||||
"email_enabled": emailEnabled,
|
"email_enabled": emailEnabled,
|
||||||
@ -159,7 +166,7 @@ func (app *appContext) InviteProxy(gc *gin.Context) {
|
|||||||
email = ""
|
email = ""
|
||||||
}
|
}
|
||||||
gcHTML(gc, http.StatusOK, "form-loader.html", gin.H{
|
gcHTML(gc, http.StatusOK, "form-loader.html", gin.H{
|
||||||
"urlBase": app.URLBase,
|
"urlBase": app.getURLBase,
|
||||||
"cssClass": app.cssClass,
|
"cssClass": app.cssClass,
|
||||||
"contactMessage": app.config.Section("ui").Key("contact_message").String(),
|
"contactMessage": app.config.Section("ui").Key("contact_message").String(),
|
||||||
"helpMessage": app.config.Section("ui").Key("help_message").String(),
|
"helpMessage": app.config.Section("ui").Key("help_message").String(),
|
||||||
|
Loading…
Reference in New Issue
Block a user