fix: adjust docker and any file for starting project

This commit is contained in:
Hafizh A. Y
2025-09-30 14:45:54 +07:00
parent c136206f2d
commit 94a6d41a61
27 changed files with 599 additions and 600 deletions
+20 -7
View File
@@ -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,
})
})