Start implementing relay management API

This commit is contained in:
Alex Gleason 2024-07-15 21:33:13 -05:00
parent 6fe034d55a
commit 3c92bd36a2
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
4 changed files with 12 additions and 9 deletions

View file

@ -159,7 +159,7 @@ app.use('/nodeinfo/*', metricsMiddleware, logger(debug));
app.use('/oauth/*', metricsMiddleware, logger(debug)); app.use('/oauth/*', metricsMiddleware, logger(debug));
app.get('/api/v1/streaming', metricsMiddleware, streamingController); app.get('/api/v1/streaming', metricsMiddleware, streamingController);
app.get('/relay', metricsMiddleware, relayController); app.all('/relay', metricsMiddleware, relayController);
app.use( app.use(
'*', '*',

View file

@ -0,0 +1,5 @@
import { AppController } from '@/app.ts';
export const managementController: AppController = (c) => {
return c.json({ error: 'Not found' }, 404);
};

View file

@ -167,10 +167,13 @@ const relayController: AppController = (c, next) => {
const upgrade = c.req.header('upgrade'); const upgrade = c.req.header('upgrade');
// NIP-11: https://github.com/nostr-protocol/nips/blob/master/11.md // NIP-11: https://github.com/nostr-protocol/nips/blob/master/11.md
if (c.req.header('accept') === 'application/nostr+json') { if (c.req.method === 'GET' && c.req.header('accept') === 'application/nostr+json') {
return relayInfoController(c, next); return relayInfoController(c, next);
} }
// NIP-86: https://github.com/nostr-protocol/nips/pull/1325
if (c.req.header('content-type') === 'application/nostr+json+rpc') {}
if (upgrade?.toLowerCase() !== 'websocket') { if (upgrade?.toLowerCase() !== 'websocket') {
return c.text('Please use a Nostr client to connect.', 400); return c.text('Please use a Nostr client to connect.', 400);
} }

View file

@ -2,16 +2,11 @@ import { HTTPException } from '@hono/hono/http-exception';
import { NostrEvent } from '@nostrify/nostrify'; import { NostrEvent } from '@nostrify/nostrify';
import { type AppContext, type AppMiddleware } from '@/app.ts'; import { type AppContext, type AppMiddleware } from '@/app.ts';
import { Conf } from '@/config.ts';
import { ReadOnlySigner } from '@/signers/ReadOnlySigner.ts'; import { ReadOnlySigner } from '@/signers/ReadOnlySigner.ts';
import { Storages } from '@/storages.ts'; import { Storages } from '@/storages.ts';
import { localRequest } from '@/utils/api.ts'; import { localRequest } from '@/utils/api.ts';
import { import { buildAuthEventTemplate, parseAuthRequest, ParseAuthRequestOpts, validateAuthEvent } from '@/utils/nip98.ts';
buildAuthEventTemplate,
parseAuthRequest,
type ParseAuthRequestOpts,
validateAuthEvent,
} from '@/utils/nip98.ts';
import { Conf } from '@/config.ts';
/** /**
* NIP-98 auth. * NIP-98 auth.