mirror of
https://github.com/aljazceru/njump.git
synced 2026-01-05 23:54:33 +01:00
Fix the protocol handling on the relay pages
This commit is contained in:
11
render.go
11
render.go
@@ -51,6 +51,17 @@ func render(w http.ResponseWriter, r *http.Request) {
|
||||
event, err := getEvent(r.Context(), code)
|
||||
if err != nil {
|
||||
// this will fail if code is a relay URL, in which case we will handle it differently
|
||||
|
||||
// If the protocol is present strip it and redirect
|
||||
if strings.HasPrefix(code, "wss:/") || strings.HasPrefix(code, "ws:/") {
|
||||
hostname := code
|
||||
hostname = strings.Replace(hostname, "wss://", "", 1)
|
||||
hostname = strings.Replace(hostname, "ws://", "", 1)
|
||||
hostname = strings.Replace(hostname, "wss:/", "", 1) // Some browsers replace upfront '//' with '/'
|
||||
hostname = strings.Replace(hostname, "ws:/", "", 1) // Some browsers replace upfront '//' with '/'
|
||||
http.Redirect(w, r, "/"+hostname, http.StatusFound)
|
||||
}
|
||||
|
||||
if urlMatcher.MatchString(code) {
|
||||
renderRelayPage(w, r)
|
||||
return
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/nbd-wtf/go-nostr"
|
||||
@@ -16,12 +15,6 @@ func renderRelayPage(w http.ResponseWriter, r *http.Request) {
|
||||
code := r.URL.Path[1:]
|
||||
|
||||
hostname := code
|
||||
if strings.HasPrefix(code, "wss://") {
|
||||
hostname = code[6:]
|
||||
}
|
||||
if strings.HasPrefix(code, "ws://") {
|
||||
hostname = code[5:]
|
||||
}
|
||||
|
||||
fmt.Println("hostname", hostname)
|
||||
|
||||
@@ -29,7 +22,7 @@ func renderRelayPage(w http.ResponseWriter, r *http.Request) {
|
||||
defer cancel()
|
||||
|
||||
// relay metadata
|
||||
info, _ := nip11.Fetch(r.Context(), code)
|
||||
info, _ := nip11.Fetch(r.Context(), hostname)
|
||||
if info == nil {
|
||||
info = &nip11.RelayInformationDocument{
|
||||
Name: hostname,
|
||||
@@ -38,7 +31,7 @@ func renderRelayPage(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// last notes
|
||||
var lastNotes []*nostr.Event
|
||||
if relay, err := pool.EnsureRelay(code); err == nil {
|
||||
if relay, err := pool.EnsureRelay(hostname); err == nil {
|
||||
lastNotes, _ = relay.QuerySync(ctx, nostr.Filter{
|
||||
Kinds: []int{1},
|
||||
Limit: 50,
|
||||
|
||||
Reference in New Issue
Block a user