init(frontend): add frontend server
also add static files and auth page
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func root(c *gin.Context) {
|
||||
authorized := c.GetBool("authorized")
|
||||
if authorized {
|
||||
c.HTML(http.StatusOK, "quotes.html", nil)
|
||||
} else {
|
||||
c.HTML(http.StatusOK, "auth.html", nil)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"github.com/H1K0/SkazaNull/api"
|
||||
"github.com/gin-contrib/sessions"
|
||||
"github.com/gin-contrib/sessions/cookie"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func Serve(addr string) {
|
||||
r := gin.Default()
|
||||
|
||||
store := cookie.NewStore([]byte("secret"))
|
||||
store.Options(sessions.Options{Path: "/"})
|
||||
r.Use(sessions.Sessions("session", store))
|
||||
|
||||
api.RegisterRoutes(r)
|
||||
|
||||
r.LoadHTMLGlob("templates/*.html")
|
||||
|
||||
r.Static("/static", "./static")
|
||||
r.GET("/", api.MiddlewareAuth, root)
|
||||
|
||||
r.Run(addr)
|
||||
}
|
||||
Reference in New Issue
Block a user