forked from prest/prest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
41 lines (35 loc) · 966 Bytes
/
config.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
package middlewares
import (
"github.com/materialagora/prest/config"
"github.com/urfave/negroni"
)
var (
app *negroni.Negroni
// MiddlewareStack on pREST
MiddlewareStack []negroni.Handler
// BaseStack Middlewares
BaseStack = []negroni.Handler{
negroni.Handler(negroni.NewRecovery()),
negroni.Handler(negroni.NewLogger()),
HandlerSet(),
}
)
func initApp() {
if len(MiddlewareStack) == 0 {
MiddlewareStack = append(MiddlewareStack, BaseStack...)
if !config.PrestConf.Debug && config.PrestConf.EnableDefaultJWT {
MiddlewareStack = append(MiddlewareStack, JwtMiddleware(config.PrestConf.JWTKey, config.PrestConf.JWTAlgo))
}
if config.PrestConf.CORSAllowOrigin != nil {
MiddlewareStack = append(MiddlewareStack, Cors(config.PrestConf.CORSAllowOrigin, config.PrestConf.CORSAllowHeaders))
}
}
app = negroni.New(MiddlewareStack...)
}
// GetApp get negroni
func GetApp() *negroni.Negroni {
if app == nil {
initApp()
}
return app
}