Redirect from root to static hosted dir and dynamic static hosted dir
This commit is contained in:
parent
3cd68987a2
commit
404224a155
3 changed files with 8 additions and 2 deletions
|
@ -1,4 +1,5 @@
|
|||
STATIC_HOSTER_HOME=/home/dave/st/
|
||||
STATIC_HOSTER_HOST_DIR=/home/dave/host-this-dir/
|
||||
STATIC_HOSTER_API_KEY=e621
|
||||
STATIC_HOSTER_PORT=4200
|
||||
STATIC_HOSTER_PORT=4200
|
||||
STATIC_HOSTER_BASE_ROUTE=/site
|
|
@ -15,6 +15,7 @@ type Environment struct {
|
|||
StaticDir string
|
||||
ApiKey string
|
||||
Port string
|
||||
BaseRoute string
|
||||
}
|
||||
|
||||
func Load() (env *Environment) {
|
||||
|
@ -30,6 +31,7 @@ func Load() (env *Environment) {
|
|||
env.StaticDir = envReader("STATIC_HOSTER_HOST_DIR", fmt.Sprintf("%s/hosted/", env.RootDir))
|
||||
env.Port = fmt.Sprintf(":%s", envReader("STATIC_HOSTER_PORT", "8080"))
|
||||
env.ApiKey = envReader("STATIC_HOSTER_API_KEY", defaultApiKey)
|
||||
env.BaseRoute = envReader("STATIC_HOSTER_BASE_ROUTE", "/home")
|
||||
if env.ApiKey == defaultApiKey {
|
||||
fmt.Printf("[STATIC-HOSTER-Warning]\t Environment Variable \"STATIC_HOSTER_API_KEY\" not set. Use default key \"%s\". DONT USE THIS FOR PRODUCTION!\n", defaultApiKey)
|
||||
}
|
||||
|
|
|
@ -22,7 +22,10 @@ func Create(env *envloader.Environment) *gin.Engine {
|
|||
c.String(http.StatusOK, "pong")
|
||||
})
|
||||
|
||||
router.Static("/home", env.StaticDir)
|
||||
router.Static(env.BaseRoute, env.StaticDir)
|
||||
router.GET("/", func(ctx *gin.Context) {
|
||||
ctx.Redirect(http.StatusPermanentRedirect, env.BaseRoute)
|
||||
})
|
||||
|
||||
router.LoadHTMLGlob(fmt.Sprintf("%s404.html", env.StaticDir))
|
||||
router.NoRoute(func(ctx *gin.Context) {
|
||||
|
|
Loading…
Reference in a new issue