Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for prerendering in the Cloudflare integration #5993

Merged
merged 4 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Cloudflare prerender branch
  • Loading branch information
matthewp committed Jan 26, 2023
commit 5481eb3db499d9f14f6d861b119591def3203f31
5 changes: 4 additions & 1 deletion packages/integrations/cloudflare/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
});
},
Expand Down Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/cloudflare/src/server.advanced.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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> };
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/cloudflare/src/server.directory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from 'astro/config';
import cloudflare from '@astrojs/cloudflare';

export default defineConfig({
adapter: cloudflare(),
output: 'server',
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@test/astro-cloudflare-prerender",
"version": "0.0.0",
"private": true,
"dependencies": {
"@astrojs/cloudflare": "workspace:*",
"astro": "workspace:*"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>
<head>
<title>Testing</title>
</head>
<body>
<h1>Testing</h1>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
export const prerender = true;
---
<html>
<head>
<title>Testing</title>
</head>
<body>
<h1>Testing</h1>
</body>
</html>
36 changes: 36 additions & 0 deletions packages/integrations/cloudflare/test/prerender.test.js
Original file line number Diff line number Diff line change
@@ -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');
});
});
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.