Initial API setup: GET and POST handlers and base permission checks.

This commit is contained in:
Jesse Malotaux 2025-03-23 15:30:08 +01:00
parent 535cf06237
commit 8b8a84aa67
15 changed files with 538 additions and 18 deletions

View file

@ -2,33 +2,26 @@ package main
import (
"log"
"mime"
"net/http"
"path/filepath"
"be/app"
"be/app/helper"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
file := "../public" // base directory
app.ApiCORS(w, r)
if r.URL.Path == "/" {
file = file + "/index.html" // default
} else {
file = file + r.URL.Path // request
if r.Method == "GET" {
app.ApiGet(w, r)
} else if r.Method == "POST" {
app.ApiPost(w, r)
}
contentType := mime.TypeByExtension(filepath.Ext(file)) // get content type
if contentType != "" {
w.Header().Set("Content-Type", contentType) // set content type header
}
log.Println(file)
log.Println("-------------")
http.ServeFile(w, r, file) // serve file
})
helper.OpenBrowser("http://localhost:6970")
log.Fatal(http.ListenAndServe(":6970", nil))
}