forked from prest/middlewares
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
40 lines (34 loc) · 894 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
package middlewares
import (
"github.com/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 {
MiddlewareStack = append(MiddlewareStack, JwtMiddleware(config.PrestConf.JWTKey))
}
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 {
// init application every time
initApp()
return app
}