Skip to content

Commit

Permalink
Initial hacky proof of concept
Browse files Browse the repository at this point in the history
  • Loading branch information
colecrouter committed Oct 18, 2022
1 parent e934bc8 commit 060d8c7
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions packages/adapter-cloudflare/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,16 @@ export default function () {

const dest_dir = `${dest}${builder.config.kit.paths.base}`;
const written_files = builder.writeClient(dest_dir);
builder.writePrerendered(dest_dir);

const prerendered_files = builder.writePrerendered(`${dest_dir}`)
.map((file) => file === 'index.html' ? file : `${file.replace(/\.[^/.]+$/, "")}`);

writeFileSync(`${dest_dir}/_redirects`, prerendered_files
.filter((file) => file !== 'index.html')
.map((file) => {
return `/${file} /${file}/index.html 200`;
})
.join('\n'));

const relativePath = posix.relative(tmp, builder.getServerDirectory());

Expand All @@ -41,7 +50,7 @@ export default function () {

writeFileSync(
`${dest}/_routes.json`,
JSON.stringify(get_routes_json(builder.config.kit.appDir, written_files))
JSON.stringify(get_routes_json(builder.config.kit.appDir, [...written_files, ...prerendered_files]))
);

writeFileSync(`${dest}/_headers`, generate_headers(builder.config.kit.appDir));
Expand Down Expand Up @@ -77,8 +86,8 @@ function get_routes_json(app_dir, assets) {
version: 1,
description: 'Generated by @sveltejs/adapter-cloudflare',
include: ['/*'],
exclude: [
`/${app_dir}/immutable/*`,
exclude: [...new Set([
`/${ 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
Expand All @@ -88,9 +97,11 @@ function get_routes_json(app_dir, assets) {
// 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((file) => file.startsWith('favicon'))
.map((file) => `/${file}`)
]
// .filter((file) => file.startsWith('favicon'))
.filter((file) => !file.startsWith('_app'))
.map((file) => `/${file.split('/')[ 0 ]}`)
.filter((file) => file !== '/_app/*')
])]
};
}

Expand Down

0 comments on commit 060d8c7

Please sign in to comment.