Skip to content

Commit 66ae0a2

Browse files
authored
fix: serve_prerendered breaks on node http server (#8890)
* fix: make serve_prerendered middleware work with node http server * changeset * lint? * confusing_branches_confuse.md * simplify
1 parent d1f7655 commit 66ae0a2

File tree

5 files changed

+12
-4
lines changed

5 files changed

+12
-4
lines changed

.changeset/late-dancers-vanish.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/adapter-node': patch
3+
---
4+
5+
fix: make serve_prerendered middleware work with node http server

packages/adapter-node/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"prepublishOnly": "pnpm build"
3333
},
3434
"devDependencies": {
35+
"@polka/url": "^1.0.0-next.21",
3536
"@sveltejs/kit": "workspace:^",
3637
"@types/node": "^16.18.6",
3738
"c8": "^7.12.0",

packages/adapter-node/rollup.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { nodeResolve } from '@rollup/plugin-node-resolve';
22
import commonjs from '@rollup/plugin-commonjs';
33
import json from '@rollup/plugin-json';
4-
import { builtinModules } from 'module';
4+
import { builtinModules } from 'node:module';
55

66
export default [
77
{

packages/adapter-node/src/handler.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import fs from 'node:fs';
33
import path from 'node:path';
44
import sirv from 'sirv';
55
import { fileURLToPath } from 'node:url';
6+
import { parse as polka_url_parser } from '@polka/url';
67
import { getRequest, setResponse } from '@sveltejs/kit/node';
78
import { Server } from 'SERVER';
89
import { manifest, prerendered } from 'MANIFEST';
@@ -50,7 +51,7 @@ function serve_prerendered() {
5051
const handler = serve(path.join(dir, 'prerendered'));
5152

5253
return (req, res, next) => {
53-
let pathname = req.path;
54+
let { pathname, search, query } = polka_url_parser(req);
5455

5556
try {
5657
pathname = decodeURIComponent(pathname);
@@ -65,8 +66,7 @@ function serve_prerendered() {
6566
// remove or add trailing slash as appropriate
6667
let location = pathname.at(-1) === '/' ? pathname.slice(0, -1) : pathname + '/';
6768
if (prerendered.has(location)) {
68-
const search = req.url.split('?')[1];
69-
if (search) location += `?${search}`;
69+
if (query) location += search;
7070
res.writeHead(308, { location }).end();
7171
} else {
7272
next();

pnpm-lock.yaml

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)