44 lines
915 B
Go
Raw Normal View History

2016-11-20 10:26:11 +00:00
package main
import (
2017-05-29 22:07:05 +00:00
"strings"
2016-11-20 10:26:11 +00:00
2016-11-22 16:37:20 +00:00
"github.com/aerogo/aero"
2016-11-20 10:26:11 +00:00
)
func init() {
2017-05-29 22:07:05 +00:00
plusRoute := "/+"
plusRouteAjax := "/_/+"
2016-11-20 10:26:11 +00:00
// This will rewrite /+UserName requests to /user/UserName
2016-11-22 16:37:20 +00:00
app.Rewrite(func(ctx *aero.RewriteContext) {
2017-05-29 22:07:05 +00:00
requestURI := ctx.URI()
2016-11-20 10:26:11 +00:00
2017-05-29 22:07:05 +00:00
if strings.HasPrefix(requestURI, plusRoute) {
newURI := "/user/"
2016-11-20 10:26:11 +00:00
userName := requestURI[2:]
2017-05-29 22:07:05 +00:00
ctx.SetURI(newURI + userName)
2017-07-02 15:51:17 +00:00
return
}
if strings.HasPrefix(requestURI, plusRouteAjax) {
2017-05-29 22:07:05 +00:00
newURI := "/_/user/"
2016-11-20 10:26:11 +00:00
userName := requestURI[4:]
2017-05-29 22:07:05 +00:00
ctx.SetURI(newURI + userName)
2017-07-02 15:51:17 +00:00
return
}
if strings.HasPrefix(requestURI, "/search/") {
searchTerm := requestURI[len("/search/"):]
ctx.Request.URL.RawQuery = "q=" + searchTerm
ctx.SetURI("/search")
}
if strings.HasPrefix(requestURI, "/_/search/") {
searchTerm := requestURI[len("/_/search/"):]
ctx.Request.URL.RawQuery = "q=" + searchTerm
ctx.SetURI("/_/search")
2016-11-20 10:26:11 +00:00
}
})
}