-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
43 lines (33 loc) · 983 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"embed"
"io/fs"
"log"
"net/http"
"github.com/jritsema/gotoolbox"
"github.com/jritsema/gotoolbox/web"
)
//go:embed nextjs/dist
//go:embed nextjs/dist/_next
//go:embed nextjs/dist/_next/static/chunks/pages/*.js
//go:embed nextjs/dist/_next/static/*/*.js
var nextFS embed.FS
func main() {
//Root at the `dist` folder generated by the Next.js app
distFS, err := fs.Sub(nextFS, "nextjs/dist")
if err != nil {
log.Fatal(err)
}
mux := http.NewServeMux()
//the static next.js app will be served under `/`
mux.Handle("/", http.FileServer(http.FS(distFS)))
//health check
mux.Handle("/health", web.Action(healthcheck))
//the API will be served under `/api`
mux.Handle("/api/items", web.Action(itemsAPI))
mux.Handle("/api/items/", web.Action(itemsAPI))
//start http server
env := gotoolbox.GetEnvWithDefault("PORT", "8080")
log.Printf("Starting HTTP server at http://localhost:%v ...", env)
log.Fatal(http.ListenAndServe(":"+env, mux))
}