afn will explod

This commit is contained in:
Ax333l 2023-01-06 17:13:27 +01:00
parent 81033b3f29
commit 24af6f54e4
No known key found for this signature in database
GPG Key ID: D2B4D85271127D23
3 changed files with 4 additions and 87 deletions

View File

@ -1,82 +0,0 @@
import fs from 'fs';
// This code was stolen from https://github.com/sveltejs/kit/blob/master/packages/adapter-static/platforms.js
// sveltekit does things like this instead of actually just using ts for some reason.
/** @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;
}
export function wrap(adapter, opts) {
if (!process.env.VERCEL) {
// we don't have to bother :)
return adapter(opts);
}
// Not exactly what adapter-static does, but it works.
opts.pages = '.vercel/output/static';
adapter = adapter(opts);
const adapt_fn = adapter.adapt;
adapter.adapt = async (builder) => {
const result = await adapt_fn(builder);
fs.writeFileSync(
'.vercel/output/config.json',
JSON.stringify({
version: 3,
routes: vercel_routes(builder)
})
);
return result;
}
return adapter;
}

1
src/routes/+layout.ts Normal file
View File

@ -0,0 +1 @@
export const prerender = true;

View File

@ -1,8 +1,6 @@
import adapter from '@sveltejs/adapter-static';
import preprocess from 'svelte-preprocess';
import { wrap } from './src/_vercel-moment.js';
/** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://github.com/sveltejs/svelte-preprocess
@ -12,9 +10,9 @@ const config = {
kit: {
// adapter-static has vercel detection, but that does not let you set a custom 404 page easily.
// Instead, we have to use a wrapper that generates a vercel config if on vercel...
adapter: wrap(adapter, {
pages: "public",
fallback: "404.html"
adapter: adapter({
pages: 'public',
fallback: '404.html'
}),
}
};