fix: url parse errors

This commit is contained in:
Sylver 2024-02-11 12:58:29 +08:00
parent 8236d9ef42
commit faae08470d
2 changed files with 5 additions and 11 deletions

View File

@ -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.

View File

@ -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 $?