mirror of
https://github.com/0ceanSlim/grain.git
synced 2024-10-29 17:16:31 +00:00
relay metadata fix
This commit is contained in:
parent
81b2eef486
commit
b0c2f98dcb
3
main.go
3
main.go
@ -59,7 +59,6 @@ func main() {
|
||||
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/", ListenAndServe)
|
||||
mux.HandleFunc("/relay-info", web.RelayInfoHandler)
|
||||
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("web/static"))))
|
||||
mux.HandleFunc("/favicon.ico", func(w http.ResponseWriter, r *http.Request) {
|
||||
http.ServeFile(w, r, "web/static/img/favicon.ico")
|
||||
@ -77,6 +76,8 @@ func ListenAndServe(w http.ResponseWriter, r *http.Request) {
|
||||
websocket.Handler(func(ws *websocket.Conn) {
|
||||
relay.WebSocketHandler(ws)
|
||||
}).ServeHTTP(w, r)
|
||||
} else if r.Header.Get("Accept") == "application/nostr+json" {
|
||||
web.RelayInfoHandler(w, r)
|
||||
} else {
|
||||
web.RootHandler(w, r)
|
||||
}
|
||||
|
15
web/http.go
15
web/http.go
@ -2,7 +2,6 @@ package web
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"grain/relay/db"
|
||||
relay "grain/relay/types"
|
||||
"html/template"
|
||||
@ -36,20 +35,6 @@ func RootHandler(w http.ResponseWriter, r *http.Request) {
|
||||
RenderTemplate(w, data, "index.html")
|
||||
}
|
||||
|
||||
func RelayInfoHandler(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Header.Get("Accept") != "application/nostr+json" {
|
||||
http.Error(w, "Unsupported Media Type", http.StatusUnsupportedMediaType)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/nostr+json")
|
||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
|
||||
w.Header().Set("Access-Control-Allow-Methods", "GET")
|
||||
|
||||
json.NewEncoder(w).Encode(relayMetadata)
|
||||
}
|
||||
|
||||
// Define the base directories for views and templates
|
||||
const (
|
||||
viewsDir = "web/views/"
|
||||
|
@ -2,6 +2,7 @@ package web
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
@ -30,3 +31,16 @@ func LoadRelayMetadata(filename string) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
func RelayInfoHandler(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Header.Get("Accept") != "application/nostr+json" {
|
||||
http.Error(w, "Unsupported Media Type", http.StatusUnsupportedMediaType)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/nostr+json")
|
||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
|
||||
w.Header().Set("Access-Control-Allow-Methods", "GET")
|
||||
|
||||
json.NewEncoder(w).Encode(relayMetadata)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user