@sveltejs/adapter-vercel 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/README.md +3 -1
- package/files/ambient.d.ts +2 -2
- package/files/entry.js +3 -3
- package/index.js +96 -2
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# adapter-vercel
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A SvelteKit adapter that creates a Vercel app.
|
|
4
|
+
|
|
5
|
+
If you're using [adapter-auto](../adapter-auto), you don't need to install this unless you need to specify Vercel-specific options, since it's already included.
|
|
4
6
|
|
|
5
7
|
## Usage
|
|
6
8
|
|
package/files/ambient.d.ts
CHANGED
package/files/entry.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import './shims';
|
|
2
2
|
import { getRequest, setResponse } from '@sveltejs/kit/node';
|
|
3
|
-
import {
|
|
3
|
+
import { Server } from 'SERVER';
|
|
4
4
|
import { manifest } from 'MANIFEST';
|
|
5
5
|
|
|
6
|
-
const
|
|
6
|
+
const server = new Server(manifest);
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* @param {import('http').IncomingMessage} req
|
|
@@ -19,5 +19,5 @@ export default async (req, res) => {
|
|
|
19
19
|
return res.end(err.reason || 'Invalid request body');
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
setResponse(res, await
|
|
22
|
+
setResponse(res, await server.respond(request));
|
|
23
23
|
};
|
package/index.js
CHANGED
|
@@ -5,6 +5,83 @@ import esbuild from 'esbuild';
|
|
|
5
5
|
|
|
6
6
|
const dir = '.vercel_build_output';
|
|
7
7
|
|
|
8
|
+
// rules for clean URLs and trailing slash handling,
|
|
9
|
+
// generated with @vercel/routing-utils
|
|
10
|
+
const redirects = {
|
|
11
|
+
always: [
|
|
12
|
+
{
|
|
13
|
+
src: '^/(?:(.+)/)?index(?:\\.html)?/?$',
|
|
14
|
+
headers: {
|
|
15
|
+
Location: '/$1/'
|
|
16
|
+
},
|
|
17
|
+
status: 308
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
src: '^/(.*)\\.html/?$',
|
|
21
|
+
headers: {
|
|
22
|
+
Location: '/$1/'
|
|
23
|
+
},
|
|
24
|
+
status: 308
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
src: '^/\\.well-known(?:/.*)?$'
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
src: '^/((?:[^/]+/)*[^/\\.]+)$',
|
|
31
|
+
headers: {
|
|
32
|
+
Location: '/$1/'
|
|
33
|
+
},
|
|
34
|
+
status: 308
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
src: '^/((?:[^/]+/)*[^/]+\\.\\w+)/$',
|
|
38
|
+
headers: {
|
|
39
|
+
Location: '/$1'
|
|
40
|
+
},
|
|
41
|
+
status: 308
|
|
42
|
+
}
|
|
43
|
+
],
|
|
44
|
+
never: [
|
|
45
|
+
{
|
|
46
|
+
src: '^/(?:(.+)/)?index(?:\\.html)?/?$',
|
|
47
|
+
headers: {
|
|
48
|
+
Location: '/$1'
|
|
49
|
+
},
|
|
50
|
+
status: 308
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
src: '^/(.*)\\.html/?$',
|
|
54
|
+
headers: {
|
|
55
|
+
Location: '/$1'
|
|
56
|
+
},
|
|
57
|
+
status: 308
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
src: '^/(.*)/$',
|
|
61
|
+
headers: {
|
|
62
|
+
Location: '/$1'
|
|
63
|
+
},
|
|
64
|
+
status: 308
|
|
65
|
+
}
|
|
66
|
+
],
|
|
67
|
+
ignore: [
|
|
68
|
+
{
|
|
69
|
+
src: '^/(?:(.+)/)?index(?:\\.html)?/?$',
|
|
70
|
+
headers: {
|
|
71
|
+
Location: '/$1'
|
|
72
|
+
},
|
|
73
|
+
status: 308
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
src: '^/(.*)\\.html/?$',
|
|
77
|
+
headers: {
|
|
78
|
+
Location: '/$1'
|
|
79
|
+
},
|
|
80
|
+
status: 308
|
|
81
|
+
}
|
|
82
|
+
]
|
|
83
|
+
};
|
|
84
|
+
|
|
8
85
|
/** @type {import('.')} **/
|
|
9
86
|
export default function ({ external = [] } = {}) {
|
|
10
87
|
return {
|
|
@@ -25,7 +102,7 @@ export default function ({ external = [] } = {}) {
|
|
|
25
102
|
|
|
26
103
|
builder.log.minor('Prerendering static pages...');
|
|
27
104
|
|
|
28
|
-
await builder.prerender({
|
|
105
|
+
const prerendered = await builder.prerender({
|
|
29
106
|
dest: `${dir}/static`
|
|
30
107
|
});
|
|
31
108
|
|
|
@@ -35,7 +112,7 @@ export default function ({ external = [] } = {}) {
|
|
|
35
112
|
|
|
36
113
|
builder.copy(files, tmp, {
|
|
37
114
|
replace: {
|
|
38
|
-
|
|
115
|
+
SERVER: `${relativePath}/index.js`,
|
|
39
116
|
MANIFEST: './manifest.js'
|
|
40
117
|
}
|
|
41
118
|
});
|
|
@@ -66,9 +143,26 @@ export default function ({ external = [] } = {}) {
|
|
|
66
143
|
builder.log.minor('Writing routes...');
|
|
67
144
|
|
|
68
145
|
builder.mkdirp(`${dir}/config`);
|
|
146
|
+
|
|
147
|
+
const prerendered_pages = Array.from(prerendered.pages, ([src, page]) => ({
|
|
148
|
+
src,
|
|
149
|
+
dest: page.file
|
|
150
|
+
}));
|
|
151
|
+
|
|
152
|
+
const prerendered_redirects = Array.from(prerendered.redirects, ([src, redirect]) => ({
|
|
153
|
+
src,
|
|
154
|
+
headers: {
|
|
155
|
+
Location: redirect.location
|
|
156
|
+
},
|
|
157
|
+
status: redirect.status
|
|
158
|
+
}));
|
|
159
|
+
|
|
69
160
|
writeFileSync(
|
|
70
161
|
`${dir}/config/routes.json`,
|
|
71
162
|
JSON.stringify([
|
|
163
|
+
...redirects[builder.trailingSlash],
|
|
164
|
+
...prerendered_pages,
|
|
165
|
+
...prerendered_redirects,
|
|
72
166
|
{
|
|
73
167
|
src: `/${builder.appDir}/.+`,
|
|
74
168
|
headers: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltejs/adapter-vercel",
|
|
3
|
-
"version": "1.0.0-next.
|
|
3
|
+
"version": "1.0.0-next.44",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/sveltejs/kit",
|
|
@@ -22,10 +22,10 @@
|
|
|
22
22
|
"index.d.ts"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"esbuild": "^0.
|
|
25
|
+
"esbuild": "^0.14.21"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@sveltejs/kit": "1.0.0-next.
|
|
28
|
+
"@sveltejs/kit": "1.0.0-next.280"
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
31
31
|
"lint": "eslint --ignore-path .gitignore \"**/*.{ts,js,svelte}\" && npm run check-format",
|