mirror of
https://github.com/Macrame-App/Macrame
synced 2025-12-29 07:19:26 +00:00
Initial API setup: GET and POST handlers and base permission checks.
This commit is contained in:
parent
535cf06237
commit
8b8a84aa67
15 changed files with 538 additions and 18 deletions
27
be/main.go
27
be/main.go
|
|
@ -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))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue