@astrojs/cloudflare 0.2.3 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +5 -5
- package/CHANGELOG.md +55 -0
- package/README.md +2 -1
- package/dist/index.js +14 -1
- package/dist/server.js +8 -6
- package/package.json +7 -5
- package/src/index.ts +15 -0
- package/src/server.ts +8 -8
- package/test/basics.test.js +31 -0
- package/test/fixtures/basics/astro.config.mjs +7 -0
- package/test/fixtures/basics/node_modules/.bin/astro +17 -0
- package/test/fixtures/basics/package.json +9 -0
- package/test/fixtures/basics/src/pages/index.astro +8 -0
- package/test/fixtures/no-output/astro.config.mjs +6 -0
- package/test/fixtures/no-output/node_modules/.bin/astro +17 -0
- package/test/fixtures/no-output/package.json +9 -0
- package/test/no-output.test.js +24 -0
- package/test/test-utils.js +67 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
[
|
|
2
|
-
[
|
|
3
|
-
[
|
|
4
|
-
[
|
|
5
|
-
[
|
|
1
|
+
[32m@astrojs/cloudflare:build: [0mcache hit, replaying output [2m709829411c5ced06[0m
|
|
2
|
+
[32m@astrojs/cloudflare:build: [0m
|
|
3
|
+
[32m@astrojs/cloudflare:build: [0m> @astrojs/cloudflare@0.4.0 build /home/runner/work/astro/astro/packages/integrations/cloudflare
|
|
4
|
+
[32m@astrojs/cloudflare:build: [0m> astro-scripts build "src/**/*.ts" && tsc
|
|
5
|
+
[32m@astrojs/cloudflare:build: [0m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,60 @@
|
|
|
1
1
|
# @astrojs/cloudflare
|
|
2
2
|
|
|
3
|
+
## 0.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#4068](https://github.com/withastro/astro/pull/4068) [`54b33d50f`](https://github.com/withastro/astro/commit/54b33d50fdb995ac056461be7e2128d911624f2d) Thanks [@matthewp](https://github.com/matthewp)! - Add explicit errors when omitting output config
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- [#4072](https://github.com/withastro/astro/pull/4072) [`a198028b0`](https://github.com/withastro/astro/commit/a198028b04234d0b8dcb0b6bcb47c5831d7a15f9) Thanks [@matthewp](https://github.com/matthewp)! - Fixes Cloudflare throwing an error for process
|
|
12
|
+
|
|
13
|
+
## 0.3.0
|
|
14
|
+
|
|
15
|
+
### Minor Changes
|
|
16
|
+
|
|
17
|
+
- [#4015](https://github.com/withastro/astro/pull/4015) [`6fd161d76`](https://github.com/withastro/astro/commit/6fd161d7691cbf9d3ffa4646e46059dfd0940010) Thanks [@matthewp](https://github.com/matthewp)! - New `output` configuration option
|
|
18
|
+
|
|
19
|
+
This change introduces a new "output target" configuration option (`output`). Setting the output target lets you decide the format of your final build, either:
|
|
20
|
+
|
|
21
|
+
- `"static"` (default): A static site. Your final build will be a collection of static assets (HTML, CSS, JS) that you can deploy to any static site host.
|
|
22
|
+
- `"server"`: A dynamic server application. Your final build will be an application that will run in a hosted server environment, generating HTML dynamically for different requests.
|
|
23
|
+
|
|
24
|
+
If `output` is omitted from your config, the default value `"static"` will be used.
|
|
25
|
+
|
|
26
|
+
When using the `"server"` output target, you must also include a runtime adapter via the `adapter` configuration. An adapter will _adapt_ your final build to run on the deployed platform of your choice (Netlify, Vercel, Node.js, Deno, etc).
|
|
27
|
+
|
|
28
|
+
To migrate: No action is required for most users. If you currently define an `adapter`, you will need to also add `output: 'server'` to your config file to make it explicit that you are building a server. Here is an example of what that change would look like for someone deploying to Netlify:
|
|
29
|
+
|
|
30
|
+
```diff
|
|
31
|
+
import { defineConfig } from 'astro/config';
|
|
32
|
+
import netlify from '@astrojs/netlify/functions';
|
|
33
|
+
|
|
34
|
+
export default defineConfig({
|
|
35
|
+
adapter: netlify(),
|
|
36
|
+
+ output: 'server',
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
* [#4018](https://github.com/withastro/astro/pull/4018) [`0cc6ede36`](https://github.com/withastro/astro/commit/0cc6ede362996b9faba57481a790d6eb7fba2045) Thanks [@okikio](https://github.com/okikio)! - Support for 404 and 500 pages in SSR
|
|
41
|
+
|
|
42
|
+
- [#3973](https://github.com/withastro/astro/pull/3973) [`5a23483ef`](https://github.com/withastro/astro/commit/5a23483efb3ba614b05a00064f84415620605204) Thanks [@matthewp](https://github.com/matthewp)! - Adds support for Astro.clientAddress
|
|
43
|
+
|
|
44
|
+
The new `Astro.clientAddress` property allows you to get the IP address of the requested user.
|
|
45
|
+
|
|
46
|
+
```astro
|
|
47
|
+
<div>Your address { Astro.clientAddress }</div>
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
This property is only available when building for SSR, and only if the adapter you are using supports providing the IP address. If you attempt to access the property in a SSG app it will throw an error.
|
|
51
|
+
|
|
52
|
+
## 0.2.4
|
|
53
|
+
|
|
54
|
+
### Patch Changes
|
|
55
|
+
|
|
56
|
+
- [#3885](https://github.com/withastro/astro/pull/3885) [`bf5d1cc1e`](https://github.com/withastro/astro/commit/bf5d1cc1e71da38a14658c615e9481f2145cc6e7) Thanks [@delucis](https://github.com/delucis)! - Integration README fixes
|
|
57
|
+
|
|
3
58
|
## 0.2.3
|
|
4
59
|
|
|
5
60
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
An SSR adapter for use with Cloudflare Pages Functions targets. Write your code in Astro/Node and deploy to Cloudflare Pages.
|
|
4
4
|
|
|
5
|
-
In your astro.config.mjs use:
|
|
5
|
+
In your `astro.config.mjs` use:
|
|
6
6
|
|
|
7
7
|
```js
|
|
8
8
|
import { defineConfig } from 'astro/config';
|
|
9
9
|
import cloudflare from '@astrojs/cloudflare';
|
|
10
10
|
|
|
11
11
|
export default defineConfig({
|
|
12
|
+
output: 'server',
|
|
12
13
|
adapter: cloudflare()
|
|
13
14
|
});
|
|
14
15
|
```
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,10 @@ function getAdapter() {
|
|
|
8
8
|
exports: ["default"]
|
|
9
9
|
};
|
|
10
10
|
}
|
|
11
|
+
const SHIM = `globalThis.process = {
|
|
12
|
+
argv: [],
|
|
13
|
+
env: {},
|
|
14
|
+
};`;
|
|
11
15
|
function createIntegration() {
|
|
12
16
|
let _config;
|
|
13
17
|
let _buildConfig;
|
|
@@ -17,6 +21,12 @@ function createIntegration() {
|
|
|
17
21
|
"astro:config:done": ({ setAdapter, config }) => {
|
|
18
22
|
setAdapter(getAdapter());
|
|
19
23
|
_config = config;
|
|
24
|
+
if (config.output === "static") {
|
|
25
|
+
throw new Error(`
|
|
26
|
+
[@astrojs/cloudflare] \`output: "server"\` is required to use this adapter. Otherwise, this adapter is not necessary to deploy a static site to Cloudflare.
|
|
27
|
+
|
|
28
|
+
`);
|
|
29
|
+
}
|
|
20
30
|
},
|
|
21
31
|
"astro:build:start": ({ buildConfig }) => {
|
|
22
32
|
_buildConfig = buildConfig;
|
|
@@ -53,7 +63,10 @@ function createIntegration() {
|
|
|
53
63
|
allowOverwrite: true,
|
|
54
64
|
format: "esm",
|
|
55
65
|
bundle: true,
|
|
56
|
-
minify: true
|
|
66
|
+
minify: true,
|
|
67
|
+
banner: {
|
|
68
|
+
js: SHIM
|
|
69
|
+
}
|
|
57
70
|
});
|
|
58
71
|
const chunksUrl = new URL("./chunks", _buildConfig.server);
|
|
59
72
|
await fs.promises.rm(chunksUrl, { recursive: true, force: true });
|
package/dist/server.js
CHANGED
|
@@ -8,12 +8,14 @@ function createExports(manifest) {
|
|
|
8
8
|
const assetRequest = new Request(`${origin}/static${pathname}`, request);
|
|
9
9
|
return env.ASSETS.fetch(assetRequest);
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
let routeData = app.match(request, { matchNotFound: true });
|
|
12
|
+
if (routeData) {
|
|
13
|
+
Reflect.set(
|
|
14
|
+
request,
|
|
15
|
+
Symbol.for("astro.clientAddress"),
|
|
16
|
+
request.headers.get("cf-connecting-ip")
|
|
17
|
+
);
|
|
18
|
+
return app.render(request, routeData);
|
|
17
19
|
}
|
|
18
20
|
return new Response(null, {
|
|
19
21
|
status: 404,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/cloudflare",
|
|
3
3
|
"description": "Deploy your site to cloudflare pages functions",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.4.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"author": "withastro",
|
|
@@ -15,22 +15,24 @@
|
|
|
15
15
|
"astro-adapter"
|
|
16
16
|
],
|
|
17
17
|
"bugs": "https://github.com/withastro/astro/issues",
|
|
18
|
-
"homepage": "https://astro.build",
|
|
18
|
+
"homepage": "https://docs.astro.build/en/guides/integrations-guide/cloudflare/",
|
|
19
19
|
"exports": {
|
|
20
20
|
".": "./dist/index.js",
|
|
21
21
|
"./server.js": "./dist/server.js",
|
|
22
22
|
"./package.json": "./package.json"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"esbuild": "^0.14.42"
|
|
25
|
+
"esbuild": "^0.14.42",
|
|
26
|
+
"wrangler": "^2.0.23"
|
|
26
27
|
},
|
|
27
28
|
"devDependencies": {
|
|
28
|
-
"astro": "1.0.0-
|
|
29
|
+
"astro": "1.0.0-rc.2",
|
|
29
30
|
"astro-scripts": "0.0.6"
|
|
30
31
|
},
|
|
31
32
|
"scripts": {
|
|
32
33
|
"build": "astro-scripts build \"src/**/*.ts\" && tsc",
|
|
33
34
|
"build:ci": "astro-scripts build \"src/**/*.ts\"",
|
|
34
|
-
"dev": "astro-scripts dev \"src/**/*.ts\""
|
|
35
|
+
"dev": "astro-scripts dev \"src/**/*.ts\"",
|
|
36
|
+
"test": "mocha --exit --timeout 30000 test/"
|
|
35
37
|
}
|
|
36
38
|
}
|
package/src/index.ts
CHANGED
|
@@ -11,6 +11,11 @@ export function getAdapter(): AstroAdapter {
|
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
const SHIM = `globalThis.process = {
|
|
15
|
+
argv: [],
|
|
16
|
+
env: {},
|
|
17
|
+
};`;
|
|
18
|
+
|
|
14
19
|
export default function createIntegration(): AstroIntegration {
|
|
15
20
|
let _config: AstroConfig;
|
|
16
21
|
let _buildConfig: BuildConfig;
|
|
@@ -21,6 +26,13 @@ export default function createIntegration(): AstroIntegration {
|
|
|
21
26
|
'astro:config:done': ({ setAdapter, config }) => {
|
|
22
27
|
setAdapter(getAdapter());
|
|
23
28
|
_config = config;
|
|
29
|
+
|
|
30
|
+
if (config.output === 'static') {
|
|
31
|
+
throw new Error(`
|
|
32
|
+
[@astrojs/cloudflare] \`output: "server"\` is required to use this adapter. Otherwise, this adapter is not necessary to deploy a static site to Cloudflare.
|
|
33
|
+
|
|
34
|
+
`);
|
|
35
|
+
}
|
|
24
36
|
},
|
|
25
37
|
'astro:build:start': ({ buildConfig }) => {
|
|
26
38
|
_buildConfig = buildConfig;
|
|
@@ -62,6 +74,9 @@ export default function createIntegration(): AstroIntegration {
|
|
|
62
74
|
format: 'esm',
|
|
63
75
|
bundle: true,
|
|
64
76
|
minify: true,
|
|
77
|
+
banner: {
|
|
78
|
+
js: SHIM,
|
|
79
|
+
},
|
|
65
80
|
});
|
|
66
81
|
|
|
67
82
|
// throw the server folder in the bin
|
package/src/server.ts
CHANGED
|
@@ -19,14 +19,14 @@ export function createExports(manifest: SSRManifest) {
|
|
|
19
19
|
return env.ASSETS.fetch(assetRequest);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return app.render(
|
|
22
|
+
let routeData = app.match(request, { matchNotFound: true });
|
|
23
|
+
if (routeData) {
|
|
24
|
+
Reflect.set(
|
|
25
|
+
request,
|
|
26
|
+
Symbol.for('astro.clientAddress'),
|
|
27
|
+
request.headers.get('cf-connecting-ip')
|
|
28
|
+
);
|
|
29
|
+
return app.render(request, routeData);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
return new Response(null, {
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { loadFixture, runCLI } from './test-utils.js';
|
|
2
|
+
import { expect } from 'chai';
|
|
3
|
+
import * as cheerio from 'cheerio';
|
|
4
|
+
|
|
5
|
+
describe('Basic app', () => {
|
|
6
|
+
/** @type {import('./test-utils').Fixture} */
|
|
7
|
+
let fixture;
|
|
8
|
+
|
|
9
|
+
before(async () => {
|
|
10
|
+
fixture = await loadFixture({
|
|
11
|
+
root: './fixtures/basics/',
|
|
12
|
+
});
|
|
13
|
+
await fixture.build();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('can render', async () => {
|
|
17
|
+
const { ready, stop } = runCLI('./fixtures/basics/', { silent: true });
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
await ready;
|
|
21
|
+
|
|
22
|
+
let res = await fetch(`http://localhost:8787/`);
|
|
23
|
+
expect(res.status).to.equal(200);
|
|
24
|
+
let html = await res.text();
|
|
25
|
+
let $ = cheerio.load(html);
|
|
26
|
+
expect($('h1').text()).to.equal('Testing');
|
|
27
|
+
} finally {
|
|
28
|
+
await stop();
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
|
3
|
+
|
|
4
|
+
case `uname` in
|
|
5
|
+
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
|
|
6
|
+
esac
|
|
7
|
+
|
|
8
|
+
if [ -z "$NODE_PATH" ]; then
|
|
9
|
+
export NODE_PATH="/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
|
|
10
|
+
else
|
|
11
|
+
export NODE_PATH="$NODE_PATH:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
|
|
12
|
+
fi
|
|
13
|
+
if [ -x "$basedir/node" ]; then
|
|
14
|
+
exec "$basedir/node" "$basedir/../../../../../../../astro/astro.js" "$@"
|
|
15
|
+
else
|
|
16
|
+
exec node "$basedir/../../../../../../../astro/astro.js" "$@"
|
|
17
|
+
fi
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
|
3
|
+
|
|
4
|
+
case `uname` in
|
|
5
|
+
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
|
|
6
|
+
esac
|
|
7
|
+
|
|
8
|
+
if [ -z "$NODE_PATH" ]; then
|
|
9
|
+
export NODE_PATH="/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
|
|
10
|
+
else
|
|
11
|
+
export NODE_PATH="$NODE_PATH:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
|
|
12
|
+
fi
|
|
13
|
+
if [ -x "$basedir/node" ]; then
|
|
14
|
+
exec "$basedir/node" "$basedir/../../../../../../../astro/astro.js" "$@"
|
|
15
|
+
else
|
|
16
|
+
exec node "$basedir/../../../../../../../astro/astro.js" "$@"
|
|
17
|
+
fi
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { loadFixture } from './test-utils.js';
|
|
2
|
+
import { expect } from 'chai';
|
|
3
|
+
|
|
4
|
+
describe('Missing output config', () => {
|
|
5
|
+
/** @type {import('./test-utils').Fixture} */
|
|
6
|
+
let fixture;
|
|
7
|
+
|
|
8
|
+
before(async () => {
|
|
9
|
+
fixture = await loadFixture({
|
|
10
|
+
root: './fixtures/no-output/',
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('throws during the build', async () => {
|
|
15
|
+
let error = undefined;
|
|
16
|
+
try {
|
|
17
|
+
await fixture.build();
|
|
18
|
+
} catch (err) {
|
|
19
|
+
error = err;
|
|
20
|
+
}
|
|
21
|
+
expect(error).to.not.be.equal(undefined);
|
|
22
|
+
expect(error.message).to.include(`output: "server"`);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { loadFixture as baseLoadFixture } from '../../../astro/test/test-utils.js';
|
|
2
|
+
import { spawn } from 'child_process';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
|
|
5
|
+
export { fixLineEndings } from '../../../astro/test/test-utils.js';
|
|
6
|
+
|
|
7
|
+
export function loadFixture(config) {
|
|
8
|
+
if (config?.root) {
|
|
9
|
+
config.root = new URL(config.root, import.meta.url);
|
|
10
|
+
}
|
|
11
|
+
return baseLoadFixture(config);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const wranglerPath = fileURLToPath(
|
|
15
|
+
new URL('../node_modules/wrangler/bin/wrangler.js', import.meta.url)
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
export function runCLI(basePath, { silent }) {
|
|
19
|
+
const script = fileURLToPath(new URL(`${basePath}/dist/_worker.js`, import.meta.url));
|
|
20
|
+
const p = spawn('node', [wranglerPath, 'dev', '-l', script]);
|
|
21
|
+
|
|
22
|
+
p.stderr.setEncoding('utf-8');
|
|
23
|
+
p.stdout.setEncoding('utf-8');
|
|
24
|
+
|
|
25
|
+
const timeout = 10000;
|
|
26
|
+
|
|
27
|
+
const ready = new Promise(async (resolve, reject) => {
|
|
28
|
+
const failed = setTimeout(
|
|
29
|
+
() => reject(new Error(`Timed out starting the wrangler CLI`)),
|
|
30
|
+
timeout
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
(async function () {
|
|
34
|
+
for (const msg of p.stderr) {
|
|
35
|
+
if (!silent) {
|
|
36
|
+
// eslint-disable-next-line
|
|
37
|
+
console.error(msg);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
})();
|
|
41
|
+
|
|
42
|
+
for await (const msg of p.stdout) {
|
|
43
|
+
if (!silent) {
|
|
44
|
+
// eslint-disable-next-line
|
|
45
|
+
console.log(msg);
|
|
46
|
+
}
|
|
47
|
+
if (msg.includes(`Listening on`)) {
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
clearTimeout(failed);
|
|
53
|
+
resolve();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
ready,
|
|
58
|
+
stop() {
|
|
59
|
+
p.kill();
|
|
60
|
+
return new Promise((resolve) => {
|
|
61
|
+
p.addListener('exit', () => {
|
|
62
|
+
resolve();
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|