49 lines
941 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
)
2017-10-02 00:09:05 +00:00
// rewrite will rewrite certain routes
func rewrite(ctx *aero.RewriteContext) {
2017-10-01 22:31:44 +00:00
requestURI := ctx.URI()
// User profiles
if strings.HasPrefix(requestURI, "/+") {
newURI := "/user/"
userName := requestURI[2:]
ctx.SetURI(newURI + userName)
return
}
if strings.HasPrefix(requestURI, "/_/+") {
newURI := "/_/user/"
userName := requestURI[4:]
ctx.SetURI(newURI + userName)
return
}
// Search
if strings.HasPrefix(requestURI, "/search/") {
searchTerm := requestURI[len("/search/"):]
ctx.Request.URL.RawQuery = "q=" + searchTerm
ctx.SetURI("/search")
return
}
if strings.HasPrefix(requestURI, "/_/search/") {
searchTerm := requestURI[len("/_/search/"):]
ctx.Request.URL.RawQuery = "q=" + searchTerm
ctx.SetURI("/_/search")
return
}
// Analytics
if requestURI == "/dark-flame-master" {
ctx.SetURI("/api/new/analytics")
return
}
2016-11-20 10:26:11 +00:00
}