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 query params being empty #774

Merged
merged 2 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
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