Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fatal error when parsing URLs in Node adapter #802

Merged
merged 4 commits into from
Mar 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/silver-elephants-tap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/adapter-node': patch
---

Fix fatal error when trying to parse URLs of incoming requests
5 changes: 5 additions & 0 deletions .changeset/witty-eyes-relax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/adapter-vercel': patch
---

Simplify parsing of URLS of incoming requests
2 changes: 1 addition & 1 deletion packages/adapter-node/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const assets_handler = sirv(join(__dirname, '/assets'), {

polka()
.use(compression({ threshold: 0 }), assets_handler, prerendered_handler, async (req, res) => {
const parsed = new URL(req.url || '');
const parsed = new URL(req.url || '', 'http://localhost');
const rendered = await app.render({
method: req.method,
headers: req.headers, // TODO: what about repeated headers, i.e. string[]
Expand Down
3 changes: 1 addition & 2 deletions packages/adapter-vercel/src/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { URL } from 'url';
import { get_body } from '@sveltejs/kit/http';

export default async (req, res) => {
const host = `${req.headers['x-forwarded-proto']}://${req.headers.host}`;
const { pathname, searchParams } = new URL(req.url || '', host);
const { pathname, searchParams } = new URL(req.url || '', 'http://localhost');

const { render } = await import('./server/app.mjs');

Expand Down