Browse Source
Basic relay metadata, include name and icons Add script to reload on config changes Updated ReadMe to reflect our changestest/local-setup
13 changed files with 427 additions and 19 deletions
@ -0,0 +1,50 @@ |
|||||||
|
#!/usr/bin/env bash |
||||||
|
# Development server with auto-restart on config file changes. |
||||||
|
# |
||||||
|
# Normal code changes (controllers, templates, etc.) are still hot-reloaded |
||||||
|
# by Phoenix automatically. This script only handles the cases Phoenix can't: |
||||||
|
# config/config.exs, config/dev.exs, and config/runtime.exs. |
||||||
|
# |
||||||
|
# Usage: |
||||||
|
# chmod +x dev.sh |
||||||
|
# source .env && ./dev.sh |
||||||
|
|
||||||
|
set -euo pipefail |
||||||
|
|
||||||
|
CONFIG_FILES=( |
||||||
|
config/config.exs |
||||||
|
config/dev.exs |
||||||
|
config/runtime.exs |
||||||
|
) |
||||||
|
|
||||||
|
cleanup() { |
||||||
|
if [ -n "${SERVER_PID:-}" ] && kill -0 "$SERVER_PID" 2>/dev/null; then |
||||||
|
echo "" |
||||||
|
echo "[dev] Stopping server (pid $SERVER_PID)..." |
||||||
|
kill "$SERVER_PID" |
||||||
|
wait "$SERVER_PID" 2>/dev/null || true |
||||||
|
fi |
||||||
|
exit 0 |
||||||
|
} |
||||||
|
|
||||||
|
trap cleanup INT TERM |
||||||
|
|
||||||
|
echo "[dev] Watching config files for changes: ${CONFIG_FILES[*]}" |
||||||
|
echo "[dev] Normal code changes are still hot-reloaded automatically." |
||||||
|
echo "[dev] Press Ctrl+C to stop." |
||||||
|
echo "" |
||||||
|
|
||||||
|
while true; do |
||||||
|
echo "[dev] Starting server..." |
||||||
|
mix phx.server & |
||||||
|
SERVER_PID=$! |
||||||
|
|
||||||
|
# Block until any config file is modified |
||||||
|
inotifywait -q -e modify "${CONFIG_FILES[@]}" 2>/dev/null |
||||||
|
|
||||||
|
echo "" |
||||||
|
echo "[dev] Config changed — restarting server..." |
||||||
|
kill "$SERVER_PID" 2>/dev/null |
||||||
|
wait "$SERVER_PID" 2>/dev/null || true |
||||||
|
echo "" |
||||||
|
done |
||||||
@ -0,0 +1,33 @@ |
|||||||
|
defmodule GcIndexRelayWeb.Plugs.RelayInfo do |
||||||
|
@moduledoc """ |
||||||
|
Serves the NIP-11 relay information document. |
||||||
|
|
||||||
|
When a GET / request arrives with `Accept: application/nostr+json`, this plug |
||||||
|
intercepts it and returns the relay metadata as JSON before the browser pipeline's |
||||||
|
`:accepts` check can reject it with a 406. |
||||||
|
|
||||||
|
Configuration is read from `config :gc_index_relay, :relay_info` — edit that key |
||||||
|
in config/config.exs to describe your relay instance. |
||||||
|
""" |
||||||
|
|
||||||
|
import Plug.Conn |
||||||
|
|
||||||
|
def init(opts), do: opts |
||||||
|
|
||||||
|
def call(%Plug.Conn{method: "GET", request_path: "/"} = conn, _opts) do |
||||||
|
accept = conn |> get_req_header("accept") |> Enum.join(",") |
||||||
|
|
||||||
|
if String.contains?(accept, "application/nostr+json") do |
||||||
|
relay_info = Application.get_env(:gc_index_relay, :relay_info, []) |> Map.new() |
||||||
|
|
||||||
|
conn |
||||||
|
|> put_resp_content_type("application/nostr+json") |
||||||
|
|> send_resp(200, Jason.encode!(relay_info)) |
||||||
|
|> halt() |
||||||
|
else |
||||||
|
conn |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
def call(conn, _opts), do: conn |
||||||
|
end |
||||||
|
Before Width: | Height: | Size: 152 B After Width: | Height: | Size: 5.1 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 218 KiB |
|
After Width: | Height: | Size: 26 KiB |
Loading…
Reference in new issue