initialize backend project
Signed-off-by: Tobias Erbshäußer <tobias@tesoft.dev>
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
.idea
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "net/http"
|
||||||
|
|
||||||
|
type ApiHandler struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewApiHandler() *ApiHandler {
|
||||||
|
// TODO
|
||||||
|
return &ApiHandler{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (api *ApiHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="WEB_MODULE" version="4">
|
||||||
|
<component name="Go" enabled="true" />
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
module backend
|
||||||
|
|
||||||
|
go 1.25
|
||||||
@@ -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