@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.
@@ -2,8 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- require('./shims-24e5b259.js');
6
- var app_js = require('./server/app.js');
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
- /** @type {import('@sveltejs/kit').App} */
22
- const app = new app_js.App(manifest);
20
+ const app = new _0APP.App(manifest);
23
21
 
24
22
  return async (event) => {
25
- const { httpMethod, headers, rawUrl, body, isBase64Encoded } = event;
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.body
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 {Record<string, string | string[]>} headers
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
- for (const key in headers) {
83
- const value = headers[key];
84
- const target = Array.isArray(value) ? m : h;
85
- target[key] = value;
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
@@ -3,7 +3,7 @@
3
3
  require('node:fs');
4
4
  require('node:path');
5
5
  var node_worker_threads = require('node:worker_threads');
6
- var shims = require('./shims-24e5b259.js');
6
+ var shims = require('./shims.js');
7
7
  require('node:http');
8
8
  require('node:https');
9
9
  require('node:zlib');