28 lines
545 B
Go
Raw Normal View History

2016-11-20 19:26:11 +09:00
package main
import (
2017-05-30 00:07:05 +02:00
"strings"
2016-11-20 19:26:11 +09:00
2016-11-23 01:37:20 +09:00
"github.com/aerogo/aero"
2016-11-20 19:26:11 +09:00
)
func init() {
2017-05-30 00:07:05 +02:00
plusRoute := "/+"
plusRouteAjax := "/_/+"
2016-11-20 19:26:11 +09:00
// This will rewrite /+UserName requests to /user/UserName
2016-11-23 01:37:20 +09:00
app.Rewrite(func(ctx *aero.RewriteContext) {
2017-05-30 00:07:05 +02:00
requestURI := ctx.URI()
2016-11-20 19:26:11 +09:00
2017-05-30 00:07:05 +02:00
if strings.HasPrefix(requestURI, plusRoute) {
newURI := "/user/"
2016-11-20 19:26:11 +09:00
userName := requestURI[2:]
2017-05-30 00:07:05 +02:00
ctx.SetURI(newURI + userName)
} else if strings.HasPrefix(requestURI, plusRouteAjax) {
newURI := "/_/user/"
2016-11-20 19:26:11 +09:00
userName := requestURI[4:]
2017-05-30 00:07:05 +02:00
ctx.SetURI(newURI + userName)
2016-11-20 19:26:11 +09:00
}
})
}