more robust controller
This commit is contained in:
parent
48e041a929
commit
2aa7f9bebf
@ -1,7 +1,13 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"encoding/gob"
|
||||
"time"
|
||||
|
||||
"github.com/flosch/pongo2/v4"
|
||||
"github.com/gin-contrib/cors"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/ratelimit"
|
||||
)
|
||||
|
||||
func Init() *gin.Engine {
|
||||
@ -11,11 +17,26 @@ func Init() *gin.Engine {
|
||||
app.Use(gin.Logger())
|
||||
app.Use(gin.Recovery())
|
||||
|
||||
// op-sec stuff
|
||||
rl = ratelimit.New(100) // 100 req/s
|
||||
app.Use(cors.New(cors.Config{AllowOrigins: []string{"http://localhost", "http://127.0.0.1"}}))
|
||||
app.Use(rateLimitMiddleware)
|
||||
|
||||
// static files
|
||||
app.Static("/public", "./public")
|
||||
|
||||
// HTML templates
|
||||
app.HTMLRender = templatePath("views")
|
||||
|
||||
// register gob
|
||||
gob.Register(pongo2.Context{})
|
||||
gob.Register(time.Time{})
|
||||
|
||||
// routes
|
||||
templateDataGroup := app.Group("/", templateDataMiddleware)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return app
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user