Created
March 15, 2017 15:52
-
-
Save jarlyyn/57ac8e2dc950e9c7715de27149481319 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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