fix logging around relays

This commit is contained in:
hzrd149 2024-09-26 09:06:08 -05:00
parent a367dee259
commit 88a9229633
2 changed files with 12 additions and 5 deletions

View File

@ -7,7 +7,7 @@ server {
proxy_cache request_cache; proxy_cache request_cache;
proxy_cache_valid 200 60m; proxy_cache_valid 200 60m;
proxy_cache_valid 404 10m; proxy_cache_valid 404 10m;
proxy_cache_key $uri; proxy_cache_key $host$uri;
proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504; proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
add_header X-Cache $upstream_cache_status; add_header X-Cache $upstream_cache_status;
@ -16,8 +16,8 @@ server {
expires 30d; expires 30d;
add_header Cache-Control "public, no-transform"; add_header Cache-Control "public, no-transform";
proxy_pass http://nsite;
proxy_set_header Host $host; proxy_set_header Host $host;
proxy_pass http://nsite;
} }
# Manual cache invalidation ( cant use proxy_cache_purge ) # Manual cache invalidation ( cant use proxy_cache_purge )

View File

@ -50,12 +50,19 @@ app.use(async (ctx, next) => {
const pubkey = (ctx.state.pubkey = await resolveNpubFromHostname(ctx.hostname)); const pubkey = (ctx.state.pubkey = await resolveNpubFromHostname(ctx.hostname));
if (pubkey) { if (pubkey) {
console.log(`${pubkey}: Fetching relays`);
let relays = await userRelays.get<string[] | undefined>(pubkey); let relays = await userRelays.get<string[] | undefined>(pubkey);
if (!relays) { if (!relays) {
console.log(`${pubkey}: Fetching relays`);
relays = await getUserOutboxes(pubkey); relays = await getUserOutboxes(pubkey);
if (relays) await userRelays.set(pubkey, relays); if (relays) {
await userRelays.set(pubkey, relays);
console.log(`${pubkey}: Found ${relays.length} relays`);
} else {
relays = [];
await userServers.set(pubkey, [], 30_000);
console.log(`${pubkey}: Failed to find relays`);
}
} }
console.log(`${pubkey}: Searching for ${ctx.path}`); console.log(`${pubkey}: Searching for ${ctx.path}`);