@sveltejs/adapter-cloudflare
Advanced tools
Comparing version 1.0.0-next.36 to 1.0.0-next.37
@@ -5,1 +5,8 @@ import { Adapter } from '@sveltejs/kit'; | ||
export default function plugin(): Adapter; | ||
export interface RoutesJSONSpec { | ||
version: 1; | ||
description: string; | ||
include: string[]; | ||
exclude: string[]; | ||
} |
55
index.js
@@ -26,3 +26,3 @@ import { writeFileSync } from 'fs'; | ||
builder.writeClient(dest); | ||
const written_files = builder.writeClient(dest); | ||
builder.writePrerendered(dest); | ||
@@ -32,9 +32,19 @@ | ||
builder.log.info( | ||
`adapter-cloudfare is writing its own _headers file. If you have your own, you should duplicate the headers contained in: ${dest}/_headers` | ||
); | ||
writeFileSync( | ||
`${tmp}/manifest.js`, | ||
`export const manifest = ${builder.generateManifest({ | ||
relativePath | ||
})};\n\nexport const prerendered = new Set(${JSON.stringify(builder.prerendered.paths)});\n` | ||
`export const manifest = ${builder.generateManifest({ relativePath })};\n\n` + | ||
`export const prerendered = new Set(${JSON.stringify(builder.prerendered.paths)});\n` | ||
); | ||
writeFileSync( | ||
`${dest}/_routes.json`, | ||
JSON.stringify(get_routes_json(builder.config.kit.appDir, written_files)) | ||
); | ||
writeFileSync(`${dest}/_headers`, generate_headers(builder.config.kit.appDir)); | ||
builder.copy(`${files}/worker.js`, `${tmp}/_worker.js`, { | ||
@@ -60,1 +70,38 @@ replace: { | ||
} | ||
/** | ||
* @param {string} app_dir | ||
* @param {string[]} assets | ||
* @returns {import('.').RoutesJSONSpec} | ||
*/ | ||
function get_routes_json(app_dir, assets) { | ||
return { | ||
version: 1, | ||
description: 'Generated by @sveltejs/adapter-cloudflare', | ||
include: ['/*'], | ||
exclude: [ | ||
`/${app_dir}/immutable/*`, | ||
...assets | ||
// We're being conservative by not excluding all assets in | ||
// /static just yet. If there are any upstream auth rules to | ||
// protect certain things (e.g. a PDF that requires auth), | ||
// then we wouldn't want to prevent those requests from going | ||
// to the user functions worker. | ||
// We do want to show an example of a _routes.json that | ||
// excludes more than just /_app/immutable/*, and favicons | ||
// are a reasonable choice | ||
.filter((filePath) => filePath.includes('favicon')) | ||
] | ||
}; | ||
} | ||
/** @param {string} app_dir */ | ||
function generate_headers(app_dir) { | ||
return ` | ||
# === START AUTOGENERATED SVELTE IMMUTABLE HEADERS === | ||
/${app_dir}/immutable/* | ||
Cache-Control: public, immutable, max-age=31536000 | ||
X-Robots-Tag: noindex | ||
# === END AUTOGENERATED SVELTE IMMUTABLE HEADERS === | ||
`.trim(); | ||
} |
{ | ||
"name": "@sveltejs/adapter-cloudflare", | ||
"version": "1.0.0-next.36", | ||
"version": "1.0.0-next.37", | ||
"repository": { | ||
@@ -5,0 +5,0 @@ "type": "git", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12782
193