forked from sveltejs/kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
platforms.js
82 lines (74 loc) · 1.6 KB
/
platforms.js
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import fs from 'fs';
/**
* @typedef {{
* name: string;
* test: () => boolean;
* defaults: (config: any) => import('./index').AdapterOptions; // TODO
* done: (builder: import('@sveltejs/kit').Builder) => void;
* }}
* Platform */
/** @param {import('@sveltejs/kit').Builder} builder */
function vercel_routes(builder) {
/** @type {any[]} */
const routes = [
{
src: `/${builder.config.kit.appDir}/immutable/.+`,
headers: {
'cache-control': 'public, immutable, max-age=31536000'
}
}
];
// explicit redirects
for (const [src, redirect] of builder.prerendered.redirects) {
routes.push({
src,
headers: {
Location: redirect.location
},
status: redirect.status
});
}
// prerendered pages
for (const [src, page] of builder.prerendered.pages) {
routes.push({
src,
dest: `${builder.config.kit.appDir}/prerendered/${page.file}`
});
}
// implicit redirects (trailing slashes)
for (const [src] of builder.prerendered.pages) {
if (src !== '/') {
routes.push({
src: src.endsWith('/') ? src.slice(0, -1) : src + '/',
headers: {
location: src
},
status: 308
});
}
}
routes.push({
handle: 'filesystem'
});
return routes;
}
/** @type {Platform[]} */
export const platforms = [
{
name: 'Vercel',
test: () => !!process.env.VERCEL,
defaults: (config) => ({
pages: `.vercel/output/static/${config.kit.appDir}/prerendered`,
assets: '.vercel/output/static'
}),
done: (builder) => {
fs.writeFileSync(
'.vercel/output/config.json',
JSON.stringify({
version: 3,
routes: vercel_routes(builder)
})
);
}
}
];