Skip to content

Instantly share code, notes, and snippets.

@jarlyyn
Created March 15, 2017 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jarlyyn/57ac8e2dc950e9c7715de27149481319 to your computer and use it in GitHub Desktop.
Save jarlyyn/57ac8e2dc950e9c7715de27149481319 to your computer and use it in GitHub Desktop.
func NewApp() http.Handler {
var SimpleRoot = simpleroot.New(simpleroot.NewCacheVerifier(Settings), BlockCache)
SimpleRoot.BlockDuration = 20 * time.Second
httpError := httperror.New()
httpError.OnStatus(404, func(w http.ResponseWriter, r *http.Request, status int) {
Render.RenderError(w, "404", nil, status)
})
httpError.OnError(func(w http.ResponseWriter, r *http.Request, status int) {
Render.RenderError(w, "500", nil, status)
})
httpError.IgnoreStatus(422)
App = middleware.New()
App.Use(misc.ElapsedTime, misc.PoweredBy("herb"), httpError.ServrMiddleware)
router = httprouter.New()
router.StripPrefix("/public").HandleFunc(misc.ServeFiles(http.Dir(resourespath + "/public/")))
router.GET("/").
Use(indexCache).
HandleFunc(IndexAction)
router.GET("/site/index").
Use(indexCache).
HandleFunc(IndexAction)
router.GET("/index.php").
Use(indexCache).
HandleFunc(IndexAction)
router.GET("/site/blogi/*path").
Use(purgeTitleInUrl, blogiCache).
HandleFunc(BlogiAction)
router.GET("/site/blog/:keyword").
Use(blogCache).
HandleFunc(BlogAction)
router.GET("/site/catalog/:keyword").
Use(categoryCache).
HandleFunc(CategoryAction)
router.GET("/site/category/:keyword").
Use(categoryCache).
HandleFunc(CategoryAction)
router.GET("/site/catalogs").
Use(categoriesCache).
HandleFunc(CategoriesAction)
router.GET("/site/categories").
Use(categoriesCache).
HandleFunc(CategoriesAction)
router.POST(AppConfig.LoginUrl).HandleFunc(SimpleRoot.LoginJSONApi(true, AppConfig.AdminUrl))
router.GET(AppConfig.LoginUrl).HandleFunc(misc.ServeFile(resourespath + "/public/adminpanel/login.html"))
router.GET(AppConfig.AdminUrl).
Use(SimpleRoot.VerifyCookieMiddleware(AppConfig.LoginUrl)).
Use(Csrf.SetCsrfTokenMiddleware).
HandleFunc(misc.ServeFile(resourespath + "/admin/index.html"))
router.POST("/install").HandleFunc(SimpleRoot.InstallRoot(AppConfig.Install))
router.StripPrefix("/admin/public").
Use(SimpleRoot.VerifyCookieMiddleware("")).
HandleFunc(misc.ServeFiles(http.Dir(resourespath + "/admin/public/")))
routerAdmin := httprouter.New()
routerAdmin.Use(SimpleRoot.VerifyCookieMiddleware(""))
routerAdmin.Use(Csrf.VerifyHeader)
routerAdmin.GET("/nodes").HandleFunc(NodesJsonApi)
routerAdmin.POST("/nodes").HandleFunc(NodeCreateJsonApi)
routerAdmin.GET("/nodes/:id").HandleFunc(NodeJsonApi)
routerAdmin.PUT("/nodes/:id").HandleFunc(NodeUpdateJsonApi)
routerAdmin.DELETE("/nodes/:id").HandleFunc(NodeDeleteJsonApi)
routerAdmin.GET("/categories").HandleFunc(CategoriesJsonApi)
routerAdmin.POST("/categories").HandleFunc(CategoryCreateJsonApi)
routerAdmin.GET("/categories/:id").HandleFunc(CategoryJsonApi)
routerAdmin.PUT("/categories/:id").HandleFunc(CategoryUpdateJsonApi)
routerAdmin.DELETE("/categories/:id").HandleFunc(CategoryDeleteJsonApi)
router.StripPrefix("/adminapi").Handle(routerAdmin)
App.Handle(router)
return App
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment