From faae08470dcafba4420e01559830f8ba5e0b06dc Mon Sep 17 00:00:00 2001 From: Sylver Date: Sun, 11 Feb 2024 12:58:29 +0800 Subject: [PATCH] fix: url parse errors --- packages/web/src/server/index.ts | 4 +++- wrapper.sh | 12 ++---------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/packages/web/src/server/index.ts b/packages/web/src/server/index.ts index cae019b..a7d3b22 100644 --- a/packages/web/src/server/index.ts +++ b/packages/web/src/server/index.ts @@ -11,6 +11,7 @@ import { renderPage } from 'vike/server'; import { PageContext } from 'vike/types'; import { REWRITES } from './rewrites'; import { fileURLToPath } from 'url'; +import url from 'url'; const fileDir = dirname(fileURLToPath(import.meta.url)); const staticDir = process.env.STATIC_DIR?.replace('{{FILE_DIR}}', fileDir) || resolve('dist/client'); @@ -39,7 +40,8 @@ async function startServer() { const instance = Fastify({ rewriteUrl: (request) => { if (!request.url) throw new Error('No url'); - const { pathname } = new URL(request.url, 'http://localhost'); + const { pathname } = url.parse(request.url); + if (!pathname) return request.url; // if discord tries to request the html of an image, redirect it straight to the image // this means the image is embedded, not the opengraph data for the image. diff --git a/wrapper.sh b/wrapper.sh index 6e08b71..0322ef4 100644 --- a/wrapper.sh +++ b/wrapper.sh @@ -1,15 +1,7 @@ #!/bin/sh -# Define a cleanup function -cleanup() { - pkill -P $$ -} - -# Trap signals and errors -trap cleanup EXIT HUP INT QUIT PIPE TERM ERR - -cd packages/api && npm run start & -cd packages/web && HOST=0.0.0.0 npm run start & +(cd packages/api && npm run start) & +(cd packages/web && HOST=0.0.0.0 npm run start) & wait -n exit $? \ No newline at end of file