focus/backend/main.go

46 lines
832 B
Go
Raw Normal View History

2023-12-27 22:23:10 +01:00
package main
import (
"fmt"
"log"
2024-01-03 18:13:54 +01:00
"os"
2023-12-27 22:23:10 +01:00
"github.com/gofiber/fiber/v2"
2023-12-27 23:38:06 +01:00
"github.com/gofiber/fiber/v2/middleware/cors"
2023-12-27 22:23:10 +01:00
_ "github.com/mattn/go-sqlite3"
"git.bhasher.com/bhasher/focus/backend/db"
"git.bhasher.com/bhasher/focus/backend/handlers"
)
func main() {
driver := "sqlite3"
port := "3000"
2024-01-03 18:13:54 +01:00
connStr := os.Getenv("DB_PATH")
if connStr == "" {
connStr = "db.sqlite"
}
2023-12-27 23:38:06 +01:00
origins := "*"
2023-12-27 22:23:10 +01:00
if err := db.InitDB(driver, connStr); err != nil {
log.Fatal(err)
}
app := fiber.New()
2023-12-27 23:38:06 +01:00
app.Use(cors.New(cors.Config{
AllowOrigins: origins,
AllowMethods: "GET,POST,PUT,DELETE",
2024-01-04 16:20:00 +01:00
AllowHeaders: "Origin, Content-Type, Accept, Cache-Control, Pragma,Expires, If-Modified-Since",
2024-01-04 22:46:29 +01:00
MaxAge: 3600,
2023-12-27 23:38:06 +01:00
}))
2024-01-04 14:13:27 +01:00
// app.Use(cache.New())
2024-01-04 12:56:04 +01:00
2023-12-30 19:42:45 +01:00
handlers.APIRouter(app.Group("/api"))
2023-12-29 03:08:08 +01:00
2023-12-27 22:23:10 +01:00
log.Fatal(app.Listen(fmt.Sprintf(":%v", port)))
}