mirror of
https://github.com/lordmathis/lemma.git
synced 2025-11-05 15:44:21 +00:00
Set up static routing on be
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/go-chi/chi/v5/middleware"
|
||||
@@ -14,7 +15,6 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
// Initialize database
|
||||
dbPath := os.Getenv("NOVAMD_DB_PATH")
|
||||
if dbPath == "" {
|
||||
@@ -38,8 +38,26 @@ func main() {
|
||||
r.Use(middleware.Logger)
|
||||
r.Use(middleware.Recoverer)
|
||||
|
||||
// Set up routes
|
||||
api.SetupRoutes(r, database, fs)
|
||||
// Set up API routes
|
||||
r.Route("/api/v1", func(r chi.Router) {
|
||||
api.SetupRoutes(r, database, fs)
|
||||
})
|
||||
|
||||
// Set up static file server
|
||||
staticPath := os.Getenv("NOVAMD_STATIC_PATH")
|
||||
if staticPath == "" {
|
||||
staticPath = "../frontend/dist"
|
||||
}
|
||||
fileServer := http.FileServer(http.Dir(staticPath))
|
||||
r.Get("/*", func(w http.ResponseWriter, r *http.Request) {
|
||||
filePath := filepath.Join(staticPath, r.URL.Path)
|
||||
_, err := os.Stat(filePath)
|
||||
if os.IsNotExist(err) {
|
||||
http.ServeFile(w, r, filepath.Join(staticPath, "index.html"))
|
||||
return
|
||||
}
|
||||
fileServer.ServeHTTP(w, r)
|
||||
})
|
||||
|
||||
// Start server
|
||||
port := os.Getenv("NOVAMD_PORT")
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
func SetupRoutes(r chi.Router, db *db.DB, fs *filesystem.FileSystem) {
|
||||
r.Route("/api/v1", func(r chi.Router) {
|
||||
r.Route("/", func(r chi.Router) {
|
||||
r.Route("/settings", func(r chi.Router) {
|
||||
r.Get("/", GetSettings(db))
|
||||
r.Post("/", UpdateSettings(db))
|
||||
|
||||
Reference in New Issue
Block a user