@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.
@@ -1,5 +1,5 @@
1
- import './shims-c8fba98f.js';
2
- import { App } from './server/app.js';
1
+ import './shims.js';
2
+ import { App } from '0APP';
3
3
  import 'node:http';
4
4
  import 'node:https';
5
5
  import 'node:zlib';
@@ -9,39 +9,21 @@ import 'node:url';
9
9
  import 'net';
10
10
 
11
11
  /**
12
- *
13
12
  * @param {import('@sveltejs/kit').SSRManifest} manifest
14
13
  * @returns {import('@netlify/functions').Handler}
15
14
  */
16
15
  function init(manifest) {
17
- /** @type {import('@sveltejs/kit').App} */
18
16
  const app = new App(manifest);
19
17
 
20
18
  return async (event) => {
21
- const { httpMethod, headers, rawUrl, body, isBase64Encoded } = event;
22
-
23
- const encoding = isBase64Encoded ? 'base64' : 'utf-8';
24
- const rawBody = typeof body === 'string' ? Buffer.from(body, encoding) : body;
25
-
26
- const rendered = await app.render({
27
- url: rawUrl,
28
- method: httpMethod,
29
- headers,
30
- rawBody
31
- });
32
-
33
- if (!rendered) {
34
- return {
35
- statusCode: 404,
36
- body: 'Not found'
37
- };
38
- }
19
+ const rendered = await app.render(to_request(event));
39
20
 
40
21
  const partial_response = {
41
22
  statusCode: rendered.status,
42
23
  ...split_headers(rendered.headers)
43
24
  };
44
25
 
26
+ // TODO this is probably wrong now?
45
27
  if (rendered.body instanceof Uint8Array) {
46
28
  // Function responses should be strings (or undefined), and responses with binary
47
29
  // content should be base64 encoded and set isBase64Encoded to true.
@@ -55,14 +37,35 @@ function init(manifest) {
55
37
 
56
38
  return {
57
39
  ...partial_response,
58
- body: rendered.body
40
+ body: await rendered.text()
59
41
  };
60
42
  };
61
43
  }
62
44
 
45
+ /**
46
+ * @param {import('@netlify/functions').HandlerEvent} event
47
+ * @returns {Request}
48
+ */
49
+ function to_request(event) {
50
+ const { httpMethod, headers, rawUrl, body, isBase64Encoded } = event;
51
+
52
+ /** @type {RequestInit} */
53
+ const init = {
54
+ method: httpMethod,
55
+ headers: new Headers(headers)
56
+ };
57
+
58
+ if (httpMethod !== 'GET' && httpMethod !== 'HEAD') {
59
+ const encoding = isBase64Encoded ? 'base64' : 'utf-8';
60
+ init.body = typeof body === 'string' ? Buffer.from(body, encoding) : body;
61
+ }
62
+
63
+ return new Request(rawUrl, init);
64
+ }
65
+
63
66
  /**
64
67
  * Splits headers into two categories: single value and multi value
65
- * @param {Record<string, string | string[]>} headers
68
+ * @param {Headers} headers
66
69
  * @returns {{
67
70
  * headers: Record<string, string>,
68
71
  * multiValueHeaders: Record<string, string[]>
@@ -75,11 +78,14 @@ function split_headers(headers) {
75
78
  /** @type {Record<string, string[]>} */
76
79
  const m = {};
77
80
 
78
- for (const key in headers) {
79
- const value = headers[key];
80
- const target = Array.isArray(value) ? m : h;
81
- target[key] = value;
82
- }
81
+ headers.forEach((value, key) => {
82
+ if (key === 'set-cookie') {
83
+ m[key] = value.split(', ');
84
+ } else {
85
+ h[key] = value;
86
+ }
87
+ });
88
+
83
89
  return {
84
90
  headers: h,
85
91
  multiValueHeaders: m
@@ -1,7 +1,7 @@
1
1
  import 'node:fs';
2
2
  import 'node:path';
3
3
  import { MessageChannel } from 'node:worker_threads';
4
- import { F as FormData, a as File } from './shims-c8fba98f.js';
4
+ import { F as FormData, a as File } from './shims.js';
5
5
  import 'node:http';
6
6
  import 'node:https';
7
7
  import 'node:zlib';