1
0

Setup Golang server with Vue3 using InertiaJS

This commit is contained in:
2024-10-27 20:59:26 +01:00
commit 2e284cbff9
10 changed files with 6665 additions and 0 deletions

34
server.go Normal file
View File

@@ -0,0 +1,34 @@
package main
import (
inertia "github.com/romsar/gonertia"
"log"
"net/http"
)
func main() {
i, err := inertia.NewFromFile("./root.html")
if err != nil {
log.Fatal(err)
}
mux := http.NewServeMux()
mux.Handle("/", i.Middleware(homeHandler(i)))
mux.Handle("/build/", http.StripPrefix("/build/", http.FileServer(http.Dir("./serve/build"))))
http.ListenAndServe(":8080", mux)
}
func homeHandler(i *inertia.Inertia) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
err := i.Render(w, r, "Home/Index", inertia.Props{
"text": "From Golang",
})
if err != nil {
return
}
}
return http.HandlerFunc(fn)
}