MarketingSystemDataTool/server/internal/api/router.go

29 lines
757 B
Go

package api
import (
"database/sql"
"net/http"
"os"
)
func NewRouter(metaDB *sql.DB, marketingDB *sql.DB) http.Handler {
mux := http.NewServeMux()
mux.Handle("/api/templates", TemplatesHandler(metaDB, marketingDB))
mux.Handle("/api/templates/", TemplatesHandler(metaDB, marketingDB))
mux.Handle("/api/exports", ExportsHandler(metaDB, marketingDB))
mux.Handle("/api/exports/", ExportsHandler(metaDB, marketingDB))
sd := staticDir()
mux.Handle("/", http.FileServer(http.Dir(sd)))
return mux
}
func staticDir() string {
if _, err := os.Stat("web/index.html"); err == nil {
return "web"
}
if _, err := os.Stat("../web/index.html"); err == nil {
return "../web"
}
return "web"
}