Skip to content

Commit 5a8cb30

Browse files
author
James Bray
committed
Fix you latest sveltekit version
1 parent c6e1045 commit 5a8cb30

File tree

4 files changed

+48
-29
lines changed

4 files changed

+48
-29
lines changed

index.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,33 +24,34 @@ module.exports = function ({ out = 'build' } = {}) {
2424
mkdirSync(server_directory, { recursive: true });
2525
}
2626

27-
builder.utils.log.minor('Copying assets');
28-
builder.utils.copy_client_files(static_directory);
29-
builder.utils.copy_static_files(static_directory);
27+
builder.log.minor('Copying assets');
28+
builder.writeClient(static_directory);
29+
builder.writeStatic(static_directory);
3030

3131

32-
builder.utils.log.minor('Copying server');
33-
builder.utils.copy_server_files(out);
32+
builder.log.minor('Copying server');
33+
builder.writeServer(out);
3434
copyFileSync(`${__dirname}/files/serverless.js`, `${server_directory}/_serverless.js`);
3535
copyFileSync(`${__dirname}/files/shims.js`, `${server_directory}/shims.js`);
3636

3737

38-
builder.utils.log.minor('Building lambda');
38+
builder.log.minor('Building lambda');
3939
esbuild.buildSync({
4040
entryPoints: [`${server_directory}/_serverless.js`],
4141
outfile: `${server_directory}/serverless.js`,
4242
inject: [join(`${server_directory}/shims.js`)],
43+
external: ['node:*'],
4344
format: 'cjs',
4445
bundle: true,
4546
platform: 'node',
4647
});
4748

48-
builder.utils.log.minor('Prerendering static pages');
49-
await builder.utils.prerender({
49+
builder.log.minor('Prerendering static pages');
50+
await builder.prerender({
5051
dest: `${static_directory}`,
5152
});
5253

53-
builder.utils.log.minor('Cleanup');
54+
builder.log.minor('Cleanup');
5455
unlinkSync(`${server_directory}/_serverless.js`);
5556
unlinkSync(`${out}/app.js`);
5657
},

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"files"
2525
],
2626
"scripts": {
27-
"build": "esbuild src/serverless.js --bundle --format=esm --platform=node --external:'../app.*' --outfile=files/serverless.js && cp src/shims.js files/shims.js ",
27+
"build": "esbuild src/serverless.js --bundle --format=esm --platform=node --external:'../app.*' --external:'../manifest.*' --outfile=files/serverless.js && cp src/shims.js files/shims.js ",
2828
"prepare": "npm run build"
2929
},
3030
"devDependencies": {},

src/serverless.js

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,62 @@
1-
import { URLSearchParams } from 'url';
2-
import * as app from '../app.js';
3-
4-
app.init();
1+
import { App } from '../app.js';
2+
import { manifest } from '../manifest.js';
53

64
export async function handler(event) {
7-
const { path, headers, rawQuery, body, isBase64Encoded } = event;
5+
console.log(event)
6+
const app = new App(manifest);
7+
const { path, headers, multiValueQueryStringParameters, body, httpMethod, requestContext, isBase64Encoded } = event;
88

99
const encoding = isBase64Encoded ? 'base64' : headers['content-encoding'] || 'utf-8';
1010
const rawBody = typeof body === 'string' ? Buffer.from(body, encoding) : body;
1111

12-
const query = new URLSearchParams(rawQuery);
12+
let rawURL = `https://${requestContext.domainName}${path}${parseQuery(multiValueQueryStringParameters)}`
13+
14+
console.log(rawURL)
1315

14-
const rendered = await app.render({
15-
host: event.requestContext.domainName,
16-
method: event.httpMethod,
17-
rawBody,
18-
headers,
19-
query,
20-
path,
21-
})
16+
const rendered = await app.render(new Request(rawURL, {
17+
method: httpMethod,
18+
headers: new Headers(headers),
19+
body: rawBody,
20+
}));
2221

2322
if (rendered) {
2423
const resp = {
2524
headers: {},
2625
multiValueHeaders: {},
27-
body: rendered.body,
26+
body: await rendered.text(),
2827
statusCode: rendered.status
2928
}
30-
Object.keys(rendered.headers).forEach(k => {
31-
const v = rendered.headers[k]
29+
for (let k of rendered.headers.keys()){
30+
console.log(k)
31+
const v = rendered.headers.get(k)
3232
if (v instanceof Array) {
3333
resp.multiValueHeaders[k] = v
3434
} else {
3535
resp.headers[k] = v
3636
}
37-
})
37+
}
3838
return resp
3939
}
4040
return {
4141
statusCode: 404,
4242
body: 'Not found.'
4343
}
4444
}
45+
46+
47+
function parseQuery(queryParams) {
48+
if (!queryParams) {
49+
return '';
50+
}
51+
let queryString = '?'
52+
53+
for (let queryParamKey in queryParams) {
54+
for (let queryParamValue of queryParams[queryParamKey]) {
55+
if (queryString != '?') {
56+
queryString += '&'
57+
}
58+
queryString += `${queryParamKey}=${queryParamValue}`
59+
}
60+
}
61+
return queryString;
62+
}

0 commit comments

Comments
 (0)