Add prerendered routes to Cloudflare routes.json
This commit is contained in:
parent
25edd88cae
commit
fb06f48810
2 changed files with 16 additions and 24 deletions
|
@ -88,13 +88,11 @@ export default function createIntegration(args?: Options): AstroIntegration {
|
|||
vite.ssr.target = vite.ssr.target || 'webworker';
|
||||
}
|
||||
},
|
||||
'astro:build:done': async () => {
|
||||
console.log('BUILD DONE');
|
||||
'astro:build:done': async ({ pages }) => {
|
||||
const entryPath = fileURLToPath(new URL(_buildConfig.serverEntry, _buildConfig.server)),
|
||||
entryUrl = new URL(_buildConfig.serverEntry, _config.outDir),
|
||||
buildPath = fileURLToPath(entryUrl);
|
||||
|
||||
console.log("ENTRY", buildPath);
|
||||
await esbuild.build({
|
||||
target: 'es2020',
|
||||
platform: 'browser',
|
||||
|
@ -109,6 +107,9 @@ export default function createIntegration(args?: Options): AstroIntegration {
|
|||
},
|
||||
});
|
||||
|
||||
// Rename to worker.js
|
||||
await fs.promises.rename(buildPath, buildPath.replace(/\.mjs$/, '.js'));
|
||||
|
||||
// throw the server folder in the bin
|
||||
const serverUrl = new URL(_buildConfig.server);
|
||||
await fs.promises.rm(serverUrl, { recursive: true, force: true });
|
||||
|
@ -146,6 +147,10 @@ export default function createIntegration(args?: Options): AstroIntegration {
|
|||
.filter((file: string) => cloudflareSpecialFiles.indexOf(file) < 0)
|
||||
.map((file: string) => `/${file}`);
|
||||
|
||||
for(let page of pages) {
|
||||
staticPathList.push(prependForwardSlash(page.pathname));
|
||||
}
|
||||
|
||||
const redirectsExists = await fs.promises
|
||||
.stat(new URL('./_redirects', _config.outDir))
|
||||
.then((stat) => stat.isFile())
|
||||
|
@ -205,3 +210,7 @@ export default function createIntegration(args?: Options): AstroIntegration {
|
|||
},
|
||||
};
|
||||
}
|
||||
|
||||
function prependForwardSlash(path: string) {
|
||||
return path[0] === '/' ? path : '/' + path;
|
||||
}
|
||||
|
|
|
@ -1,18 +1,6 @@
|
|||
import { loadFixture } from './test-utils.js';
|
||||
import { expect } from 'chai';
|
||||
|
||||
process.on('exit', () => {
|
||||
console.log('process [exit]');
|
||||
});
|
||||
|
||||
process.on('uncaughtException', err => {
|
||||
console.log('uncaughtException');
|
||||
});
|
||||
|
||||
process.on('unhandledRejection', rej => {
|
||||
console.log('unhandledRejection');
|
||||
});
|
||||
|
||||
describe('Prerendering', () => {
|
||||
/** @type {import('./test-utils').Fixture} */
|
||||
let fixture;
|
||||
|
@ -21,16 +9,11 @@ describe('Prerendering', () => {
|
|||
fixture = await loadFixture({
|
||||
root: './fixtures/prerender/',
|
||||
});
|
||||
try {
|
||||
console.log("BEFORE");
|
||||
await fixture.build();
|
||||
console.log('done');
|
||||
} catch(err) {
|
||||
console.log('after build', err);
|
||||
}
|
||||
});
|
||||
|
||||
it('works', async () => {
|
||||
console.log('works');
|
||||
it('includes prerendered routes in the routes.json config', async () => {
|
||||
const routes = JSON.parse(await fixture.readFile('/_routes.json'));
|
||||
expect(routes.exclude).to.include('/one/');
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue