51 lines
1.0 KiB
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)
2017-07-02 17:51:17 +02:00
return
}
if strings.HasPrefix(requestURI, plusRouteAjax) {
2017-05-30 00:07:05 +02:00
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)
2017-07-02 17:51:17 +02:00
return
}
if strings.HasPrefix(requestURI, "/search/") {
searchTerm := requestURI[len("/search/"):]
ctx.Request.URL.RawQuery = "q=" + searchTerm
ctx.SetURI("/search")
2017-07-05 23:48:29 +02:00
return
2017-07-02 17:51:17 +02:00
}
if strings.HasPrefix(requestURI, "/_/search/") {
searchTerm := requestURI[len("/_/search/"):]
ctx.Request.URL.RawQuery = "q=" + searchTerm
ctx.SetURI("/_/search")
2017-07-05 23:48:29 +02:00
return
}
if requestURI == "/dark-flame-master" {
ctx.SetURI("/api/analytics/new")
return
2016-11-20 19:26:11 +09:00
}
})
}