fix: add development mode environment variable
This commit is contained in:
parent
43628a1a66
commit
a864e689be
2 changed files with 13 additions and 1 deletions
|
|
@ -1,3 +1,5 @@
|
||||||
|
# Adds localhost to allowed origins
|
||||||
|
DEVELOPMENT_MODE=false
|
||||||
# Port for the server
|
# Port for the server
|
||||||
PORT=8888
|
PORT=8888
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,16 @@ import (
|
||||||
"backend/internal/handler"
|
"backend/internal/handler"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func getAllowedOrigins() []string {
|
||||||
|
allowedOrigins := []string{"https://axolotlmaid.com"}
|
||||||
|
|
||||||
|
if os.Getenv("DEVELOPMENT_MODE") == "true" {
|
||||||
|
allowedOrigins = append(allowedOrigins, "http://localhost:4321")
|
||||||
|
}
|
||||||
|
|
||||||
|
return allowedOrigins
|
||||||
|
}
|
||||||
|
|
||||||
func NewRouter() {
|
func NewRouter() {
|
||||||
r := chi.NewRouter()
|
r := chi.NewRouter()
|
||||||
|
|
||||||
|
|
@ -26,7 +36,7 @@ func NewRouter() {
|
||||||
r.Use(middleware.Timeout(60 * time.Second))
|
r.Use(middleware.Timeout(60 * time.Second))
|
||||||
r.Use(httprate.LimitByRealIP(32, time.Minute))
|
r.Use(httprate.LimitByRealIP(32, time.Minute))
|
||||||
r.Use(cors.Handler(cors.Options{
|
r.Use(cors.Handler(cors.Options{
|
||||||
AllowedOrigins: []string{"https://axolotlmaid.com"},
|
AllowedOrigins: getAllowedOrigins(),
|
||||||
AllowedMethods: []string{"GET", "PATCH"},
|
AllowedMethods: []string{"GET", "PATCH"},
|
||||||
AllowedHeaders: []string{"Content-Type"},
|
AllowedHeaders: []string{"Content-Type"},
|
||||||
MaxAge: 300,
|
MaxAge: 300,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue