Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions goblog.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,8 @@ func main() {
c.File(filepath.Join("themes", activeTheme, "static", fp))
})

router.GET("/", goblog.rootHandler)
router.GET("/login", goblog.loginHandler)
getAndHead(router, "/", goblog.rootHandler)
getAndHead(router, "/login", goblog.loginHandler)
Comment thread
compscidr marked this conversation as resolved.
router.GET("/wizard", goblog._wizard.SaveToken)
router.POST("/wizard_db", updateDB)
router.POST("/test_db", testDB)
Expand Down Expand Up @@ -463,16 +463,16 @@ func (g goblog) addRoutes() {
//the json API. The json API is tested more easily. Also javascript can
//served in the html can be used to create and update posts by directly
//working with the json API.
g.router.GET("/index.php", g._blog.Home)
g.router.GET("/posts/:yyyy/:mm/:dd/:slug", g._blog.Post)
getAndHead(g.router, "/index.php", g._blog.Home)
getAndHead(g.router, "/posts/:yyyy/:mm/:dd/:slug", g._blog.Post)
// lets posts work with our without the word posts in front
g.router.GET("/:yyyy/:mm/:dd/:slug", g._blog.Post)
getAndHead(g.router, "/:yyyy/:mm/:dd/:slug", g._blog.Post)
g.router.GET("/admin/posts/:yyyy/:mm/:dd/:slug", g._admin.Post)
g.router.GET("/tag/*name", g._blog.Tag)
getAndHead(g.router, "/tag/*name", g._blog.Tag)
g.router.GET("/logout", g._blog.Logout)

g.router.GET("/search", g._blog.Search)
g.router.GET("/sitemap.xml", g._blog.Sitemap)
getAndHead(g.router, "/search", g._blog.Search)
getAndHead(g.router, "/sitemap.xml", g._blog.Sitemap)
// lets old WordPress stuff stored at wp-content/uploads work
g.router.Use(static.Serve("/wp-content", static.LocalFile("www", false)))

Expand All @@ -489,6 +489,13 @@ func (g goblog) addRoutes() {
g.router.NoRoute(g._blog.NoRoute)
}

// getAndHead registers a handler for both GET and HEAD on the given path.
// HEAD is required by the HTTP spec for any resource that supports GET.
func getAndHead(router *gin.Engine, path string, handler gin.HandlerFunc) {
router.GET(path, handler)
router.HEAD(path, handler)
}
Comment thread
compscidr marked this conversation as resolved.

func CORS() gin.HandlerFunc {
return func(c *gin.Context) {
c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
Expand Down
Loading