Skip to content

Commit

Permalink
Fix empty query params in adapter-vercel (#774)
Browse files Browse the repository at this point in the history
Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
  • Loading branch information
wiesson and benmccann authored Mar 31, 2021
1 parent 8dc89ba commit ca33a35
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .changeset/flat-pillows-think.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@sveltejs/adapter-node': patch
'@sveltejs/adapter-vercel': patch
---

Fix adapter-vercel query parsing and update adapter-node's
6 changes: 3 additions & 3 deletions packages/adapter-node/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import fs from 'fs';
import polka from 'polka';
import { dirname, join } from 'path';
import sirv from 'sirv';
import { parse, URLSearchParams, fileURLToPath } from 'url';
import { URL, fileURLToPath } from 'url';
// eslint-disable-next-line import/no-unresolved
import { get_body } from '@sveltejs/kit/http';
// App is a dynamic file built from the application layer.
Expand Down Expand Up @@ -31,13 +31,13 @@ const assets_handler = sirv(join(__dirname, '/assets'), {

polka()
.use(compression({ threshold: 0 }), assets_handler, prerendered_handler, async (req, res) => {
const parsed = parse(req.url || '');
const parsed = new URL(req.url || '');
const rendered = await app.render({
method: req.method,
headers: req.headers, // TODO: what about repeated headers, i.e. string[]
path: parsed.pathname,
body: await get_body(req),
query: new URLSearchParams(parsed.query || '')
query: parsed.searchParams
});

if (rendered) {
Expand Down
6 changes: 3 additions & 3 deletions packages/adapter-vercel/src/entry.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { URL, URLSearchParams } from 'url';
import { URL } from 'url';
// eslint-disable-next-line import/no-unresolved
import { get_body } from '@sveltejs/kit/http';

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

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

const rendered = await render({
method: req.method,
headers: req.headers,
path: pathname,
query: new URLSearchParams(query),
query: searchParams,
body: await get_body(req)
});

Expand Down

0 comments on commit ca33a35

Please sign in to comment.