Skip to content

Commit

Permalink
Fix fatal error when parsing URLs in Node adapter (#802)
Browse files Browse the repository at this point in the history
* fix parsing url in node adapter

* add changeset

* simplify vercel url parsing

* add changelog
  • Loading branch information
Conduitry authored Mar 31, 2021
1 parent 7c8c49f commit feb2db7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
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

0 comments on commit feb2db7

Please sign in to comment.