Add "behind proxy" mode to use forwarded IP headers
This commit is contained in:
parent
272ccc1929
commit
a6e05ba4c4
3 changed files with 11 additions and 2 deletions
|
|
@ -2,5 +2,6 @@ DEBUG=false
|
||||||
DEV_MODE=false
|
DEV_MODE=false
|
||||||
APP_LISTEN_ADDRESS=127.0.0.1
|
APP_LISTEN_ADDRESS=127.0.0.1
|
||||||
APP_LISTEN_PORT=3000
|
APP_LISTEN_PORT=3000
|
||||||
|
APP_BEHIND_PROXY=false
|
||||||
DATABASE_LOCATION=./people.db
|
DATABASE_LOCATION=./people.db
|
||||||
SESSIONS_LOCATION=./sessions.db
|
SESSIONS_LOCATION=./sessions.db
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ type Config struct {
|
||||||
App struct {
|
App struct {
|
||||||
ListenAddress string `env:"APP_LISTEN_ADDRESS"`
|
ListenAddress string `env:"APP_LISTEN_ADDRESS"`
|
||||||
ListenPort uint `env:"APP_LISTEN_PORT"`
|
ListenPort uint `env:"APP_LISTEN_PORT"`
|
||||||
|
BehindProxy bool `env:"APP_BEHIND_PROXY"`
|
||||||
}
|
}
|
||||||
Database struct {
|
Database struct {
|
||||||
Location string `env:"DATABASE_LOCATION"`
|
Location string `env:"DATABASE_LOCATION"`
|
||||||
|
|
|
||||||
11
main.go
11
main.go
|
|
@ -67,10 +67,17 @@ func main() {
|
||||||
|
|
||||||
pongo2.RegisterFilter("time_diff", helpers.TemplTimeDiff)
|
pongo2.RegisterFilter("time_diff", helpers.TemplTimeDiff)
|
||||||
|
|
||||||
app := fiber.New(fiber.Config{
|
fiberConfig := fiber.Config{
|
||||||
Views: engine,
|
Views: engine,
|
||||||
ErrorHandler: helpers.FiberErrorHandler,
|
ErrorHandler: helpers.FiberErrorHandler,
|
||||||
})
|
}
|
||||||
|
|
||||||
|
// If app behind proxy, use headers for IP
|
||||||
|
if config.App.BehindProxy {
|
||||||
|
fiberConfig.ProxyHeader = fiber.HeaderXForwardedFor
|
||||||
|
}
|
||||||
|
|
||||||
|
app := fiber.New(fiberConfig)
|
||||||
|
|
||||||
if config.DevMode {
|
if config.DevMode {
|
||||||
app.Static("/static", "./static")
|
app.Static("/static", "./static")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue