Skip to content

Commit

Permalink
feat: add base-url env variable to specify where to listen to
Browse files Browse the repository at this point in the history
closes #4
  • Loading branch information
simonwep committed Jul 20, 2024
1 parent 2572636 commit 5d3311d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Base url to listen for requests
GENESIS_BASE_URL=/

# Database location
GENESIS_DB_PATH=.data

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ docker run -p 8080:8080 -v "$(pwd)/.data:/app/.data" --env-file .env ghcr.io/sim

Genesis should then be accessible under port `8080`.

> [!NOTE]
> You can specify the base-url via the env variable `GENESIS_BASE_URL`.
### API

The API is kept as simple as possible, there is nothing more than user, data and account management.
Expand Down
2 changes: 2 additions & 0 deletions core/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

type AppConfig struct {
DbPath string
BaseUrl string
JWTSecret []byte
JWTExpiration time.Duration
JWTCookieAllowHTTP bool
Expand Down Expand Up @@ -45,6 +46,7 @@ var Config = func() AppConfig {

config := AppConfig{
DbPath: resolvePath(os.Getenv("GENESIS_DB_PATH")),
BaseUrl: os.Getenv("GENESIS_BASE_URL"),
JWTSecret: []byte(os.Getenv("GENESIS_JWT_SECRET")),
JWTExpiration: time.Duration(parseInt(os.Getenv("GENESIS_JWT_TOKEN_EXPIRATION"))) * time.Minute,
JWTCookieAllowHTTP: os.Getenv("GENESIS_JWT_COOKIE_ALLOW_HTTP") == "true",
Expand Down
9 changes: 6 additions & 3 deletions routes/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ func SetupRoutes() *gin.Engine {
gin.SetMode(core.Config.AppGinMode)

// Create router
router := gin.New()
root := gin.New()

// Middleware
router.Use(gin.Recovery())
root.Use(gin.Recovery())

// Wrap routes under common path
router := root.Group(core.Config.BaseUrl)

// Auth and account endpoints
router.POST("/login", Login)
Expand All @@ -37,5 +40,5 @@ func SetupRoutes() *gin.Engine {
// Heal check endpoints
router.GET("/health", Health)

return router
return root
}

0 comments on commit 5d3311d

Please sign in to comment.