mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
fix: adjust docker and any file for starting project
This commit is contained in:
+20
-7
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
@@ -43,11 +44,7 @@ func main() {
|
||||
}
|
||||
|
||||
func setupRedis() *redis.Client {
|
||||
redisURL := os.Getenv("REDIS_URL")
|
||||
if redisURL == "" {
|
||||
redisURL = "redis://redis:6379/0"
|
||||
}
|
||||
opt, err := redis.ParseURL(redisURL)
|
||||
opt, err := redis.ParseURL(config.RedisURL)
|
||||
if err != nil {
|
||||
utils.Log.Fatalf("Redis URL parse error: %v", err)
|
||||
}
|
||||
@@ -55,7 +52,7 @@ func setupRedis() *redis.Client {
|
||||
if err := rdb.Ping(context.Background()).Err(); err != nil {
|
||||
utils.Log.Fatalf("Redis ping failed: %v", err)
|
||||
}
|
||||
utils.Log.Infof("Redis connected: %s", redisURL)
|
||||
utils.Log.Infof("Redis connected: %s", config.RedisURL)
|
||||
return rdb
|
||||
}
|
||||
|
||||
@@ -70,6 +67,22 @@ func setupFiberApp() *fiber.App {
|
||||
app.Use(cors.New())
|
||||
app.Use(middleware.RecoverConfig())
|
||||
|
||||
origins := "*"
|
||||
if len(config.CORSAllowOrigins) > 0 {
|
||||
origins = strings.Join(config.CORSAllowOrigins, ",")
|
||||
}
|
||||
if config.CORSAllowCredentials && (origins == "" || origins == "*") {
|
||||
origins = "http://localhost:3000"
|
||||
}
|
||||
app.Use(cors.New(cors.Config{
|
||||
AllowOrigins: origins,
|
||||
AllowMethods: strings.Join(config.CORSAllowMethods, ","),
|
||||
AllowHeaders: strings.Join(config.CORSAllowHeaders, ","),
|
||||
ExposeHeaders: strings.Join(config.CORSExposeHeaders, ","),
|
||||
AllowCredentials: config.CORSAllowCredentials,
|
||||
MaxAge: config.CORSMaxAge,
|
||||
}))
|
||||
|
||||
return app
|
||||
}
|
||||
|
||||
@@ -86,7 +99,7 @@ func setupRoutes(app *fiber.App, db *gorm.DB, rdb *redis.Client) {
|
||||
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||
"status": "ok",
|
||||
"service": "api",
|
||||
"version": os.Getenv("VERSION"),
|
||||
"version": config.Version,
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user