1
0
Fork 0
mirror of https://github.com/benbusby/farside.git synced 2025-04-20 10:58:42 +00:00

Include original url query in redirect

Query params were previously getting ignored in farside redirects, this
updates the routing to append the original url query params to the end
of the redirected instance.
This commit is contained in:
Ben Busby 2025-02-25 11:20:13 -07:00
parent 37b0df5c36
commit 4b19ad5228
No known key found for this signature in database
GPG key ID: B9B7231E01D924A1
2 changed files with 7 additions and 9 deletions

View file

@ -1,4 +0,0 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]

View file

@ -3,6 +3,7 @@ package server
import ( import (
_ "embed" _ "embed"
"encoding/json" "encoding/json"
"fmt"
"html/template" "html/template"
"log" "log"
"net/http" "net/http"
@ -61,22 +62,22 @@ func state(w http.ResponseWriter, r *http.Request) {
} }
func baseRouting(w http.ResponseWriter, r *http.Request) { func baseRouting(w http.ResponseWriter, r *http.Request) {
routing(w, r, false) routing(w, r, false, r.URL.RawQuery)
} }
func jsRouting(w http.ResponseWriter, r *http.Request) { func jsRouting(w http.ResponseWriter, r *http.Request) {
r.URL.Path = strings.Replace(r.URL.Path, "/_", "", 1) r.URL.Path = strings.Replace(r.URL.Path, "/_", "", 1)
routing(w, r, true) routing(w, r, true, r.URL.RawQuery)
} }
func routing(w http.ResponseWriter, r *http.Request, jsEnabled bool) { func routing(w http.ResponseWriter, r *http.Request, jsEnabled bool, query string) {
value := r.PathValue("routing") value := r.PathValue("routing")
if len(value) == 0 { if len(value) == 0 {
value = r.URL.Path value = r.URL.Path
} }
url, _ := url.Parse(value) parsedURL, _ := url.Parse(value)
path := strings.TrimPrefix(url.Path, "/") path := strings.TrimPrefix(parsedURL.Path, "/")
segments := strings.Split(path, "/") segments := strings.Split(path, "/")
if len(segments[0]) == 0 { if len(segments[0]) == 0 {
@ -119,6 +120,7 @@ func routing(w http.ResponseWriter, r *http.Request, jsEnabled bool) {
w.Header().Set("Pragma", "no-cache") w.Header().Set("Pragma", "no-cache")
w.Header().Set("Expires", "0") w.Header().Set("Expires", "0")
instance += fmt.Sprintf("?%s", query)
if jsEnabled { if jsEnabled {
data := routeData{ data := routeData{
InstanceURL: instance, InstanceURL: instance,