-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathentry.js
More file actions
33 lines (26 loc) · 710 Bytes
/
entry.js
File metadata and controls
33 lines (26 loc) · 710 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { __fetch_polyfill } from '@sveltejs/kit/install-fetch';
import { getRawBody } from '@sveltejs/kit/node';
import { App } from 'APP';
import { manifest } from 'MANIFEST';
__fetch_polyfill();
const app = new App(manifest);
export default async (req, res) => {
let body;
try {
body = await getRawBody(req);
} catch (err) {
res.statusCode = err.status || 400;
return res.end(err.reason || 'Invalid request body');
}
const rendered = await app.render({
url: req.url,
method: req.method,
headers: req.headers,
rawBody: body
});
if (rendered) {
const { status, headers, body } = rendered;
return res.writeHead(status, headers).end(body);
}
return res.writeHead(404).end();
};