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';
|
vite.ssr.target = vite.ssr.target || 'webworker';
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'astro:build:done': async () => {
|
'astro:build:done': async ({ pages }) => {
|
||||||
console.log('BUILD DONE');
|
|
||||||
const entryPath = fileURLToPath(new URL(_buildConfig.serverEntry, _buildConfig.server)),
|
const entryPath = fileURLToPath(new URL(_buildConfig.serverEntry, _buildConfig.server)),
|
||||||
entryUrl = new URL(_buildConfig.serverEntry, _config.outDir),
|
entryUrl = new URL(_buildConfig.serverEntry, _config.outDir),
|
||||||
buildPath = fileURLToPath(entryUrl);
|
buildPath = fileURLToPath(entryUrl);
|
||||||
|
|
||||||
console.log("ENTRY", buildPath);
|
|
||||||
await esbuild.build({
|
await esbuild.build({
|
||||||
target: 'es2020',
|
target: 'es2020',
|
||||||
platform: 'browser',
|
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
|
// throw the server folder in the bin
|
||||||
const serverUrl = new URL(_buildConfig.server);
|
const serverUrl = new URL(_buildConfig.server);
|
||||||
await fs.promises.rm(serverUrl, { recursive: true, force: true });
|
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)
|
.filter((file: string) => cloudflareSpecialFiles.indexOf(file) < 0)
|
||||||
.map((file: string) => `/${file}`);
|
.map((file: string) => `/${file}`);
|
||||||
|
|
||||||
|
for(let page of pages) {
|
||||||
|
staticPathList.push(prependForwardSlash(page.pathname));
|
||||||
|
}
|
||||||
|
|
||||||
const redirectsExists = await fs.promises
|
const redirectsExists = await fs.promises
|
||||||
.stat(new URL('./_redirects', _config.outDir))
|
.stat(new URL('./_redirects', _config.outDir))
|
||||||
.then((stat) => stat.isFile())
|
.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 { loadFixture } from './test-utils.js';
|
||||||
import { expect } from 'chai';
|
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', () => {
|
describe('Prerendering', () => {
|
||||||
/** @type {import('./test-utils').Fixture} */
|
/** @type {import('./test-utils').Fixture} */
|
||||||
let fixture;
|
let fixture;
|
||||||
|
@ -21,16 +9,11 @@ describe('Prerendering', () => {
|
||||||
fixture = await loadFixture({
|
fixture = await loadFixture({
|
||||||
root: './fixtures/prerender/',
|
root: './fixtures/prerender/',
|
||||||
});
|
});
|
||||||
try {
|
await fixture.build();
|
||||||
console.log("BEFORE");
|
|
||||||
await fixture.build();
|
|
||||||
console.log('done');
|
|
||||||
} catch(err) {
|
|
||||||
console.log('after build', err);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('works', async () => {
|
it('includes prerendered routes in the routes.json config', async () => {
|
||||||
console.log('works');
|
const routes = JSON.parse(await fixture.readFile('/_routes.json'));
|
||||||
|
expect(routes.exclude).to.include('/one/');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue