it builds and shows the login page
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
.DEFAULT_GOAL := build
|
||||
|
||||
.PHONY:fmt vet build
|
||||
fmt:
|
||||
go fmt ./...
|
||||
|
||||
vet: fmt
|
||||
go vet ./...
|
||||
|
||||
build: vet
|
||||
cd web && pnpm run build
|
||||
go build -v -o solopm-server ./cmd/server
|
||||
|
||||
test:
|
||||
go test ./tests/...
|
||||
@@ -0,0 +1,50 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
func handler(writer http.ResponseWriter, request *http.Request) {
|
||||
templ := template.Must(template.ParseFiles("./web/dist/index.html"))
|
||||
|
||||
templ.Execute(writer, nil)
|
||||
}
|
||||
|
||||
func main() {
|
||||
err := godotenv.Load()
|
||||
if err != nil {
|
||||
log.Fatal("Error loading .env file")
|
||||
}
|
||||
|
||||
webDir := "./web/dist"
|
||||
fs := http.FileServer(http.Dir(webDir))
|
||||
|
||||
http.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) {
|
||||
if request.URL.Path != "/" {
|
||||
path := filepath.Join(webDir, filepath.Clean(request.URL.Path))
|
||||
_, err := os.Stat(path)
|
||||
if err == nil {
|
||||
fs.ServeHTTP(writer, request)
|
||||
return
|
||||
}
|
||||
}
|
||||
handler(writer, request)
|
||||
})
|
||||
|
||||
port := os.Getenv("HTTP_PORT")
|
||||
if port == "" {
|
||||
port = "8080"
|
||||
}
|
||||
addr := ":" + port
|
||||
fmt.Printf("Server listening on http://localhost%s\n", addr)
|
||||
if err := http.ListenAndServe(addr, nil); err != nil {
|
||||
log.Fatalf("server error: %v", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user