Initial commit for AI Media Hub
Some checks failed
Build and Push Docker Image / build-and-push (push) Has been cancelled
Some checks failed
Build and Push Docker Image / build-and-push (push) Has been cancelled
This commit is contained in:
59
backend/main.go
Normal file
59
backend/main.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/middleware/cors"
|
||||
"github.com/gofiber/fiber/v2/middleware/logger"
|
||||
"github.com/gofiber/websocket/v2"
|
||||
"github.com/savethenurse/ai-media-hub/backend/handlers"
|
||||
"github.com/savethenurse/ai-media-hub/backend/models"
|
||||
)
|
||||
|
||||
func main() {
|
||||
dbDir := os.Getenv("DB_DIR")
|
||||
if dbDir == "" {
|
||||
dbDir = "/app/db"
|
||||
}
|
||||
dbPath := dbDir + "/media_hub.db"
|
||||
|
||||
// Ensure DB directory exists
|
||||
os.MkdirAll(dbDir, os.ModePerm)
|
||||
|
||||
// Initialize Database
|
||||
models.InitDB(dbPath)
|
||||
|
||||
app := fiber.New()
|
||||
|
||||
app.Use(logger.New())
|
||||
app.Use(cors.New())
|
||||
|
||||
// Static files (Frontend)
|
||||
app.Static("/", "./frontend")
|
||||
|
||||
// API Routes
|
||||
api := app.Group("/api")
|
||||
api.Get("/search", handlers.SearchAndFilter)
|
||||
api.Post("/upload", handlers.UploadMedia)
|
||||
api.Post("/download", handlers.DownloadMedia)
|
||||
|
||||
// WebSocket Route
|
||||
app.Use("/ws", func(c *fiber.Ctx) error {
|
||||
if websocket.IsWebSocketUpgrade(c) {
|
||||
c.Locals("allowed", true)
|
||||
return c.Next()
|
||||
}
|
||||
return fiber.ErrUpgradeRequired
|
||||
})
|
||||
app.Get("/ws", websocket.New(handlers.WsHandler))
|
||||
|
||||
port := os.Getenv("PORT")
|
||||
if port == "" {
|
||||
port = "3000"
|
||||
}
|
||||
|
||||
log.Printf("Starting Server on port %s", port)
|
||||
app.Listen(":" + port)
|
||||
}
|
||||
Reference in New Issue
Block a user