Cloudflare prerender branch

This commit is contained in:
Matthew Phillips 2023-01-23 10:41:45 -05:00
parent 5fd9208d44
commit f135b0d94b
9 changed files with 85 additions and 3 deletions

View file

@ -49,7 +49,7 @@ export default function createIntegration(args?: Options): AstroIntegration {
build: {
client: new URL(`.${config.base}`, config.outDir),
server: new URL(`.${SERVER_BUILD_FOLDER}`, config.outDir),
serverEntry: '_worker.js',
serverEntry: '_worker.mjs',
},
});
},
@ -89,9 +89,12 @@ export default function createIntegration(args?: Options): AstroIntegration {
}
},
'astro:build:done': async () => {
console.log('BUILD DONE');
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',

View file

@ -2,7 +2,7 @@ import type { SSRManifest } from 'astro';
import { App } from 'astro/app';
import { getProcessEnvProxy } from './util.js';
process.env = getProcessEnvProxy();
//process.env = getProcessEnvProxy();
type Env = {
ASSETS: { fetch: (req: Request) => Promise<Response> };

View file

@ -2,7 +2,7 @@ import type { SSRManifest } from 'astro';
import { App } from 'astro/app';
import { getProcessEnvProxy } from './util.js';
process.env = getProcessEnvProxy();
//process.env = getProcessEnvProxy();
export function createExports(manifest: SSRManifest) {
const app = new App(manifest, false);

View file

@ -0,0 +1,7 @@
import { defineConfig } from 'astro/config';
import cloudflare from '@astrojs/cloudflare';
export default defineConfig({
adapter: cloudflare(),
output: 'server',
});

View file

@ -0,0 +1,9 @@
{
"name": "@test/astro-cloudflare-prerender",
"version": "0.0.0",
"private": true,
"dependencies": {
"@astrojs/cloudflare": "workspace:*",
"astro": "workspace:*"
}
}

View file

@ -0,0 +1,8 @@
<html>
<head>
<title>Testing</title>
</head>
<body>
<h1>Testing</h1>
</body>
</html>

View file

@ -0,0 +1,11 @@
---
export const prerender = true;
---
<html>
<head>
<title>Testing</title>
</head>
<body>
<h1>Testing</h1>
</body>
</html>

View file

@ -0,0 +1,36 @@
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;
before(async () => {
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');
});
});

View file

@ -2631,6 +2631,14 @@ importers:
'@astrojs/cloudflare': link:../../..
astro: link:../../../../../astro
packages/integrations/cloudflare/test/fixtures/prerender:
specifiers:
'@astrojs/cloudflare': workspace:*
astro: workspace:*
dependencies:
'@astrojs/cloudflare': link:../../..
astro: link:../../../../../astro
packages/integrations/deno:
specifiers:
astro: workspace:*