28 lines
545 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)
} else if strings.HasPrefix(requestURI, plusRouteAjax) {
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)
2016-11-20 10:26:11 +00:00
}
})
}