2016-11-20 10:26:11 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
|
2016-11-22 16:37:20 +00:00
|
|
|
"github.com/aerogo/aero"
|
2016-11-20 10:26:11 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
plusRoute := []byte("/+")
|
|
|
|
plusRouteAjax := []byte("/_/+")
|
|
|
|
|
|
|
|
// This will rewrite /+UserName requests to /user/UserName
|
2016-11-22 16:37:20 +00:00
|
|
|
app.Rewrite(func(ctx *aero.RewriteContext) {
|
|
|
|
requestURI := ctx.URIBytes()
|
2016-11-20 10:26:11 +00:00
|
|
|
|
|
|
|
if bytes.HasPrefix(requestURI, plusRoute) {
|
|
|
|
newURI := []byte("/user/")
|
|
|
|
userName := requestURI[2:]
|
|
|
|
newURI = append(newURI, userName...)
|
2016-11-22 16:37:20 +00:00
|
|
|
ctx.SetURIBytes(newURI)
|
2016-11-20 10:26:11 +00:00
|
|
|
} else if bytes.HasPrefix(requestURI, plusRouteAjax) {
|
|
|
|
newURI := []byte("/_/user/")
|
|
|
|
userName := requestURI[4:]
|
|
|
|
newURI = append(newURI, userName...)
|
2016-11-22 16:37:20 +00:00
|
|
|
ctx.SetURIBytes(newURI)
|
2016-11-20 10:26:11 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|