18
router.go
18
router.go
@@ -82,12 +82,13 @@ func (w *statusResponseWriter) WriteHeader(statusCode int) {
|
||||
}
|
||||
|
||||
// CreateMainRouter creates the main Gorilla router for the application.
|
||||
func CreateMainRouter(rl *rushlink, debug bool) *mux.Router {
|
||||
//
|
||||
// This function will not populate the router with an error-recovery and
|
||||
// metrics-reporting middleware. If these middleware are required, then the
|
||||
// caller should encapsulate this router inside of another router and register
|
||||
// the middlewares on the encapsulating router.
|
||||
func CreateMainRouter(rl *rushlink) *mux.Router {
|
||||
router := mux.NewRouter()
|
||||
if !debug {
|
||||
router.Use(rl.recoveryMiddleware)
|
||||
router.Use(rl.metricsMiddleware)
|
||||
}
|
||||
router.HandleFunc("/{path:img/"+staticFilenameExpr+"}", rl.staticGetHandler).Methods("GET", "HEAD")
|
||||
router.HandleFunc("/{path:css/"+staticFilenameExpr+"}", rl.staticGetHandler).Methods("GET", "HEAD")
|
||||
router.HandleFunc("/{path:js/"+staticFilenameExpr+"}", rl.staticGetHandler).Methods("GET", "HEAD")
|
||||
@@ -122,8 +123,13 @@ func StartMainServer(addr string, db *db.Database, fs *db.FileStore, rawRootURL
|
||||
rootURL: rootURL,
|
||||
}
|
||||
|
||||
router := mux.NewRouter()
|
||||
router.Use(rl.metricsMiddleware)
|
||||
router.Use(rl.recoveryMiddleware)
|
||||
router.Handle("/", CreateMainRouter(&rl))
|
||||
|
||||
srv := &http.Server{
|
||||
Handler: CreateMainRouter(&rl, false),
|
||||
Handler: router,
|
||||
Addr: addr,
|
||||
WriteTimeout: 15 * time.Second,
|
||||
ReadTimeout: 15 * time.Second,
|
||||
|
||||
Reference in New Issue
Block a user