Skip to content

Commit

Permalink
fix: url parse errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sylv committed Feb 11, 2024
1 parent 8236d9e commit faae084
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
4 changes: 3 additions & 1 deletion packages/web/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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.
Expand Down
12 changes: 2 additions & 10 deletions wrapper.sh
Original file line number Diff line number Diff line change
@@ -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 $?

0 comments on commit faae084

Please sign in to comment.