diff --git a/backend/.dockerignore b/backend/.dockerignore new file mode 100644 index 0000000..df4930e --- /dev/null +++ b/backend/.dockerignore @@ -0,0 +1,2 @@ +lst_backend.exe +lst.net.exe \ No newline at end of file diff --git a/backend/Dockerfile b/backend/Dockerfile index da573ea..98db621 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -3,19 +3,25 @@ FROM golang:1.24.4-alpine3.22 AS builder WORKDIR /app COPY go.mod go.sum ./ -# COPY VERSION ./VERSION +COPY docs /app/docs/ +COPY frontend /app/frontend/ RUN go mod download COPY . . + RUN CGO_ENABLED=0 GOOS=linux go build -o lst_go ./main.go FROM alpine:latest WORKDIR /root/ +# Copy only the binary (no need for source files) +RUN mkdir -p ./docs ./frontend + COPY --from=builder /app/lst_go . -# COPY --from=builder /app/VERSION ./ +COPY --from=builder /app/docs ./docs/ +COPY --from=builder /app/frontend ./frontend/ # create the volume paths RUN mkdir -p /data diff --git a/backend/main.go b/backend/main.go index 33aad19..01aa0f3 100644 --- a/backend/main.go +++ b/backend/main.go @@ -4,39 +4,89 @@ import ( "fmt" "log" "net/http" + "os" "github.com/gin-gonic/gin" "github.com/joho/godotenv" ) func main() { - - err := godotenv.Load("../.env") - if err != nil { - log.Fatal("Error loading .env file") + // Load .env only in dev (not Docker/production) + if os.Getenv("RUNNING_IN_DOCKER") != "true" { + err := godotenv.Load("../.env") + if err != nil { + log.Println("Warning: .env file not found (ok in Docker/production)") + } } - // name := os.Getenv("LSTV2") + // Set basePath dynamically + basePath := "/" + if os.Getenv("APP_ENV") != "production" { + basePath = "/lst" // Dev only + } // fmt.Println(name) fmt.Println("Welcome to lst backend where all the fun happens.") r := gin.Default() - // Serve Docusaurus static files - r.StaticFS("/lst/docs", http.Dir("docs")) + // // --- Add Redirects Here --- + // // Redirect root ("/") to "/app" or "/lst/app" + // r.GET("/", func(c *gin.Context) { + // c.Redirect(http.StatusMovedPermanently, basePath+"/app") + // }) - r.GET("/api/ping", func(c *gin.Context) { + // // Redirect "/lst" (if applicable) to "/lst/app" + // if basePath == "/lst" { + // r.GET("/lst", func(c *gin.Context) { + // c.Redirect(http.StatusMovedPermanently, basePath+"/app") + // }) + // } + + // Serve Docusaurus static files + r.StaticFS(basePath+"/docs", http.Dir("docs")) + r.StaticFS(basePath+"/app", http.Dir("frontend")) + + r.GET(basePath+"/api/ping", func(c *gin.Context) { c.JSON(200, gin.H{"message": "pong"}) }) - r.Any("/api", errorApiLoc) - r.Any("/", errorLoc) + r.Any(basePath+"/api", errorApiLoc) + + // // Serve static assets for Vite app + // r.Static("/lst/app/assets", "./dist/app/assets") + + // // Catch-all for Vite app routes + // r.NoRoute(func(c *gin.Context) { + // path := c.Request.URL.Path + + // // Don't handle API, assets, or docs + // if strings.HasPrefix(path, "/lst/api") || + // strings.HasPrefix(path, "/lst/app/assets") || + // strings.HasPrefix(path, "/lst/docs") { + // c.JSON(404, gin.H{"error": "Not found"}) + // return + // } + + // // Serve index.html for all /lst/app routes + // if strings.HasPrefix(path, "/lst/app") { + // c.File("./dist/app/index.html") + // return + // } + + // c.JSON(404, gin.H{"error": "Not found"}) + // }) r.Run(":8080") } -func errorLoc(c *gin.Context) { - c.JSON(http.StatusBadRequest, gin.H{"message": "welcome to lst system you might have just encountered an incorrect area of the app"}) -} +// func serveViteApp(c *gin.Context) { +// // Set proper Content-Type for HTML +// c.Header("Content-Type", "text/html") +// c.File("./dist/index.html") +// } + +// func errorLoc(c *gin.Context) { +// c.JSON(http.StatusBadRequest, gin.H{"message": "welcome to lst system you might have just encountered an incorrect area of the app"}) +// } func errorApiLoc(c *gin.Context) { c.JSON(http.StatusBadRequest, gin.H{"message": "looks like you have encountered an api route that dose not exist"}) }