-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
routes.go
49 lines (42 loc) · 1.01 KB
/
routes.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
44
45
46
47
48
49
package routes
import (
"embed"
"io/fs"
"log"
"net/http"
"github.com/gin-gonic/gin"
"github.com/mrinjamul/words-zen/api/handler"
)
// ViewsFs for static files
var ViewsFs embed.FS
func InitRoutes(routes *gin.Engine) {
// Serve the frontend
// This will ensure that the angular files are served correctly
fsRoot, err := fs.Sub(ViewsFs, "views")
if err != nil {
log.Println(err)
}
routes.NoRoute(gin.WrapH(http.FileServer(http.FS(fsRoot))))
// routes.StaticFS("/", http.FS(fsRoot))
// routes.NoRoute(func(ctx *gin.Context) {
// dir, file := path.Split(ctx.Request.RequestURI)
// ext := filepath.Ext(file)
// if file == "" || ext == "" {
// ctx.File("./views" + "/index.html")
// } else {
// ctx.File("./views" + "/" + path.Join(dir, file))
// }
// })
// health check
routes.GET("/api/health", func(c *gin.Context) {
c.JSON(
http.StatusOK,
gin.H{
"health": "ok",
},
)
})
// Backend API
routes.GET("/api/:phrase", handler.GetHandler)
routes.POST("/api", handler.PostHandler)
}