initialize backend project
Signed-off-by: Tobias Erbshäußer <tobias@tesoft.dev>
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
port := os.Getenv("PORT")
|
||||
if port == "" {
|
||||
port = "8080"
|
||||
}
|
||||
|
||||
staticFolder := os.Getenv("STATIC_FOLDER")
|
||||
if staticFolder == "" {
|
||||
staticFolder = "static"
|
||||
}
|
||||
|
||||
fsHandler := http.FileServer(http.Dir(staticFolder))
|
||||
apiHandler := NewApiHandler()
|
||||
|
||||
mux := http.NewServeMux()
|
||||
mux.Handle("/", fsHandler)
|
||||
mux.Handle("/api/", apiHandler)
|
||||
|
||||
log.Println("Listening on port", port)
|
||||
err := http.ListenAndServe(":"+port, mux)
|
||||
if err != nil {
|
||||
log.Fatalln(err.Error())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user