fix(web-proxy): actually working metrics, misc fixes
This commit is contained in:
parent
b2bfe93013
commit
4ea21177ec
@ -64,7 +64,7 @@ func (p ProxyHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// CORS headers
|
||||
rw.Header().Add("Access-Control-Allow-Origin", "*")
|
||||
rw.Header().Add("Access-Control-Request-Method", r.Method)
|
||||
rw.Header().Add("Access-Control-Allow-Methods", "*")
|
||||
rw.Header().Add("Access-Control-Allow-Credentials", "true")
|
||||
rw.Header().Add("Access-Control-Allow-Headers", "Content-Type, Authorization, sentry-trace")
|
||||
rw.Header().Add("Access-Control-Max-Age", "86400")
|
||||
@ -98,7 +98,7 @@ func logTimeElapsed(resp *http.Response) error {
|
||||
"route": cleanPath(r.Host, r.URL.Path),
|
||||
}).Observe(elapsed.Seconds())
|
||||
|
||||
log.Printf("[%s %s] \"%s %s%s\" %d - %vms\n", r.Header.Get("Fly-Client-IP"), r.Header.Get("User-Agent"), r.Method, r.Host, r.URL.Path, resp.StatusCode, elapsed.Milliseconds())
|
||||
log.Printf("[%s] \"%s %s%s\" %d - %vms %s\n", r.Header.Get("Fly-Client-IP"), r.Method, r.Host, r.URL.Path, resp.StatusCode, elapsed.Milliseconds(), r.Header.Get("User-Agent"))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -28,28 +28,28 @@ func proxyTo(host string) *httputil.ReverseProxy {
|
||||
return rp
|
||||
}
|
||||
|
||||
var systemsRegex = regexp.MustCompile("systems/[^/]+")
|
||||
var membersRegex = regexp.MustCompile("members/[^/]+")
|
||||
var groupsRegex = regexp.MustCompile("groups/[^/]+")
|
||||
var switchesRegex = regexp.MustCompile("switches/[^/]+")
|
||||
var guildsRegex = regexp.MustCompile("guilds/[^/]+")
|
||||
var messagesRegex = regexp.MustCompile("messages/[^/]+")
|
||||
var systemsRegex = regexp.MustCompile("systems/[^/{}]+")
|
||||
var membersRegex = regexp.MustCompile("members/[^/{}]+")
|
||||
var groupsRegex = regexp.MustCompile("groups/[^/{}]+")
|
||||
var switchesRegex = regexp.MustCompile("switches/[^/{}]+")
|
||||
var guildsRegex = regexp.MustCompile("guilds/[^/{}]+")
|
||||
var messagesRegex = regexp.MustCompile("messages/[^/{}]+")
|
||||
|
||||
func cleanPath(host, path string) string {
|
||||
if host != "api.pluralkit.me" {
|
||||
return ""
|
||||
}
|
||||
|
||||
if !(strings.HasPrefix(host, "/v2") || strings.HasPrefix(host, "/private")) {
|
||||
if !(strings.HasPrefix(path, "/v2") || strings.HasPrefix(path, "/private")) {
|
||||
return ""
|
||||
}
|
||||
|
||||
path = systemsRegex.ReplaceAllString(path, "{systemRef}")
|
||||
path = membersRegex.ReplaceAllString(path, "{memberRef}")
|
||||
path = groupsRegex.ReplaceAllString(path, "{groupRef}")
|
||||
path = switchesRegex.ReplaceAllString(path, "{switchRef}")
|
||||
path = guildsRegex.ReplaceAllString(path, "{guild_id}")
|
||||
path = messagesRegex.ReplaceAllString(path, "{message_id}")
|
||||
path = systemsRegex.ReplaceAllString(path, "systems/{systemRef}")
|
||||
path = membersRegex.ReplaceAllString(path, "members/{memberRef}")
|
||||
path = groupsRegex.ReplaceAllString(path, "groups/{groupRef}")
|
||||
path = switchesRegex.ReplaceAllString(path, "switches/{switchRef}")
|
||||
path = guildsRegex.ReplaceAllString(path, "guilds/{guild_id}")
|
||||
path = messagesRegex.ReplaceAllString(path, "messages/{message_id}")
|
||||
|
||||
return path
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user