From 30ab41907d3d02836f3bc9e32e5f821a9024c7f6 Mon Sep 17 00:00:00 2001 From: reya Date: Tue, 23 Jan 2024 13:54:15 +0700 Subject: [PATCH] fix --- src/daemon/run.ts | 8 +++++--- src/daemon/web/authorize.ts | 4 ++-- templates/authorizeRequest.handlebar | 2 +- templates/createAccount.handlebar | 2 +- templates/error.handlebar | 2 +- templates/login.handlebar | 2 +- templates/redirect.handlebar | 2 +- 7 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/daemon/run.ts b/src/daemon/run.ts index 19f3e65..ca7a90f 100644 --- a/src/daemon/run.ts +++ b/src/daemon/run.ts @@ -174,6 +174,8 @@ class Daemon { async startWebAuth() { if (!this.config.authPort) return; + const path = new URL(this.config.baseUrl as string).pathname.replace(/\/+$/, ''); + this.fastify.register(FastifyView, { engine: { handlebars: Handlebars @@ -182,9 +184,9 @@ class Daemon { this.fastify.listen({ port: this.config.authPort }); - this.fastify.get('/requests/:id', authorizeRequestWebHandler); - this.fastify.post('/requests/:id', processRequestWebHandler); - this.fastify.post('/register/:id', processRegistrationWebHandler); + this.fastify.get(`${path}/requests/:id`, authorizeRequestWebHandler); + this.fastify.post(`${path}/requests/:id`, processRequestWebHandler); + this.fastify.post(`${path}/register/:id`, processRegistrationWebHandler); } async startKeys() { diff --git a/src/daemon/web/authorize.ts b/src/daemon/web/authorize.ts index 95798c0..868e347 100644 --- a/src/daemon/web/authorize.ts +++ b/src/daemon/web/authorize.ts @@ -49,7 +49,7 @@ export async function authorizeRequestWebHandler(request, reply) { const record = await getAndValidateStateOfRequest(request); const url = new URL(request.url, `http://${request.headers.host}`); const callbackUrl = url.searchParams.get("callbackUrl"); - const baseUrl = new URL(request.url).pathname?.split('/')?.[1] || '/'; + const baseUrl = new URL(request.url).pathname?.split('/')?.[1]?.replace(/\/+$/, '') || '/'; const method = record.method; let nip05: string | undefined; @@ -164,7 +164,7 @@ export async function processRegistrationWebHandler(request, reply) { try { const record = await getAndValidateStateOfRequest(request); const body = request.body; - const baseUrl = new URL(request.url).pathname?.split('/')?.[1] || '/'; + const baseUrl = new URL(request.url).pathname?.split('/')?.[1]?.replace(/\/+$/, '') || '/'; // we serialize the payload again and store it // along with the allowed flag diff --git a/templates/authorizeRequest.handlebar b/templates/authorizeRequest.handlebar index c5beec5..dcff0ea 100644 --- a/templates/authorizeRequest.handlebar +++ b/templates/authorizeRequest.handlebar @@ -3,7 +3,7 @@ - Authorize Request - Nostr + Authorize Request