2017-10-02 00:31:44 +02:00

49 lines
941 B
Go

package main
import (
"strings"
"github.com/aerogo/aero"
)
// Rewrite will rewrite certain routes
func Rewrite(ctx *aero.RewriteContext) {
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
}
}