@sveltejs/adapter-netlify 1.0.0-next.40 → 1.0.0-next.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/files/cjs/handler.js +36 -30
- package/files/cjs/{multipart-parser-52bc5518.js → multipart-parser-76542256.js} +1 -1
- package/files/cjs/shims.js +6529 -8
- package/files/esm/handler.js +35 -29
- package/files/esm/{multipart-parser-a360c9ae.js → multipart-parser-211c7dba.js} +1 -1
- package/files/esm/shims.js +6520 -8
- package/index.js +6 -2
- package/package.json +3 -3
- package/files/cjs/shims-24e5b259.js +0 -6530
- package/files/esm/shims-c8fba98f.js +0 -6520
package/files/cjs/handler.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
require('./shims
|
|
6
|
-
var
|
|
5
|
+
require('./shims.js');
|
|
6
|
+
var _0APP = require('0APP');
|
|
7
7
|
require('node:http');
|
|
8
8
|
require('node:https');
|
|
9
9
|
require('node:zlib');
|
|
@@ -13,39 +13,21 @@ require('node:url');
|
|
|
13
13
|
require('net');
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
17
16
|
* @param {import('@sveltejs/kit').SSRManifest} manifest
|
|
18
17
|
* @returns {import('@netlify/functions').Handler}
|
|
19
18
|
*/
|
|
20
19
|
function init(manifest) {
|
|
21
|
-
|
|
22
|
-
const app = new app_js.App(manifest);
|
|
20
|
+
const app = new _0APP.App(manifest);
|
|
23
21
|
|
|
24
22
|
return async (event) => {
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
const encoding = isBase64Encoded ? 'base64' : 'utf-8';
|
|
28
|
-
const rawBody = typeof body === 'string' ? Buffer.from(body, encoding) : body;
|
|
29
|
-
|
|
30
|
-
const rendered = await app.render({
|
|
31
|
-
url: rawUrl,
|
|
32
|
-
method: httpMethod,
|
|
33
|
-
headers,
|
|
34
|
-
rawBody
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
if (!rendered) {
|
|
38
|
-
return {
|
|
39
|
-
statusCode: 404,
|
|
40
|
-
body: 'Not found'
|
|
41
|
-
};
|
|
42
|
-
}
|
|
23
|
+
const rendered = await app.render(to_request(event));
|
|
43
24
|
|
|
44
25
|
const partial_response = {
|
|
45
26
|
statusCode: rendered.status,
|
|
46
27
|
...split_headers(rendered.headers)
|
|
47
28
|
};
|
|
48
29
|
|
|
30
|
+
// TODO this is probably wrong now?
|
|
49
31
|
if (rendered.body instanceof Uint8Array) {
|
|
50
32
|
// Function responses should be strings (or undefined), and responses with binary
|
|
51
33
|
// content should be base64 encoded and set isBase64Encoded to true.
|
|
@@ -59,14 +41,35 @@ function init(manifest) {
|
|
|
59
41
|
|
|
60
42
|
return {
|
|
61
43
|
...partial_response,
|
|
62
|
-
body: rendered.
|
|
44
|
+
body: await rendered.text()
|
|
63
45
|
};
|
|
64
46
|
};
|
|
65
47
|
}
|
|
66
48
|
|
|
49
|
+
/**
|
|
50
|
+
* @param {import('@netlify/functions').HandlerEvent} event
|
|
51
|
+
* @returns {Request}
|
|
52
|
+
*/
|
|
53
|
+
function to_request(event) {
|
|
54
|
+
const { httpMethod, headers, rawUrl, body, isBase64Encoded } = event;
|
|
55
|
+
|
|
56
|
+
/** @type {RequestInit} */
|
|
57
|
+
const init = {
|
|
58
|
+
method: httpMethod,
|
|
59
|
+
headers: new Headers(headers)
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
if (httpMethod !== 'GET' && httpMethod !== 'HEAD') {
|
|
63
|
+
const encoding = isBase64Encoded ? 'base64' : 'utf-8';
|
|
64
|
+
init.body = typeof body === 'string' ? Buffer.from(body, encoding) : body;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return new Request(rawUrl, init);
|
|
68
|
+
}
|
|
69
|
+
|
|
67
70
|
/**
|
|
68
71
|
* Splits headers into two categories: single value and multi value
|
|
69
|
-
* @param {
|
|
72
|
+
* @param {Headers} headers
|
|
70
73
|
* @returns {{
|
|
71
74
|
* headers: Record<string, string>,
|
|
72
75
|
* multiValueHeaders: Record<string, string[]>
|
|
@@ -79,11 +82,14 @@ function split_headers(headers) {
|
|
|
79
82
|
/** @type {Record<string, string[]>} */
|
|
80
83
|
const m = {};
|
|
81
84
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
headers.forEach((value, key) => {
|
|
86
|
+
if (key === 'set-cookie') {
|
|
87
|
+
m[key] = value.split(', ');
|
|
88
|
+
} else {
|
|
89
|
+
h[key] = value;
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
87
93
|
return {
|
|
88
94
|
headers: h,
|
|
89
95
|
multiValueHeaders: m
|