@astrojs/cloudflare 3.1.2 → 4.0.1
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 +24 -0
- package/README.md +12 -10
- package/dist/server.advanced.d.ts +0 -1
- package/dist/server.advanced.js +4 -2
- package/dist/server.directory.d.ts +0 -1
- package/dist/server.directory.js +4 -2
- package/dist/util.d.ts +1 -0
- package/dist/util.js +15 -0
- package/package.json +6 -3
- package/src/server.advanced.ts +6 -3
- package/src/server.directory.ts +6 -3
- package/src/util.ts +16 -0
- package/test/basics.test.js +1 -0
- package/test/fixtures/basics/astro.config.mjs +3 -0
- package/test/fixtures/basics/src/pages/index.astro +1 -0
- package/test/wrangler.toml +4 -0
- package/dist/shim.d.ts +0 -0
- package/dist/shim.js +0 -4
- package/src/shim.ts +0 -4
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
[
|
|
2
|
-
[
|
|
3
|
-
[
|
|
4
|
-
[
|
|
5
|
-
[
|
|
1
|
+
[35m@astrojs/cloudflare:build: [0mcache hit, replaying output [2m17da9601b72c4888[0m
|
|
2
|
+
[35m@astrojs/cloudflare:build: [0m
|
|
3
|
+
[35m@astrojs/cloudflare:build: [0m> @astrojs/cloudflare@4.0.1 build /home/runner/work/astro/astro/packages/integrations/cloudflare
|
|
4
|
+
[35m@astrojs/cloudflare:build: [0m> astro-scripts build "src/**/*.ts" && tsc
|
|
5
|
+
[35m@astrojs/cloudflare:build: [0m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @astrojs/cloudflare
|
|
2
2
|
|
|
3
|
+
## 4.0.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#5301](https://github.com/withastro/astro/pull/5301) [`a79a37cad`](https://github.com/withastro/astro/commit/a79a37cad549b21f91599ff86899e456d9dcc7df) Thanks [@bluwy](https://github.com/bluwy)! - Fix environment variables usage in worker output and warn if environment variables are accessedd too early
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`88c1bbe3a`](https://github.com/withastro/astro/commit/88c1bbe3a71f85e92f42f13d0f310c6b2a264ade), [`a79a37cad`](https://github.com/withastro/astro/commit/a79a37cad549b21f91599ff86899e456d9dcc7df)]:
|
|
10
|
+
- astro@1.6.5
|
|
11
|
+
|
|
12
|
+
## 4.0.0
|
|
13
|
+
|
|
14
|
+
### Major Changes
|
|
15
|
+
|
|
16
|
+
- [#5290](https://github.com/withastro/astro/pull/5290) [`b2b291d29`](https://github.com/withastro/astro/commit/b2b291d29143703cece0d12c8e74b2e1151d2061) Thanks [@matthewp](https://github.com/matthewp)! - Handle base configuration in adapters
|
|
17
|
+
|
|
18
|
+
This allows adapters to correctly handle `base` configuration. Internally Astro now matches routes when the URL includes the `base`.
|
|
19
|
+
|
|
20
|
+
Adapters now also have access to the `removeBase` method which will remove the `base` from a pathname. This is useful to look up files for static assets.
|
|
21
|
+
|
|
22
|
+
### Patch Changes
|
|
23
|
+
|
|
24
|
+
- Updated dependencies [[`b2b291d29`](https://github.com/withastro/astro/commit/b2b291d29143703cece0d12c8e74b2e1151d2061), [`97e2b6ad7`](https://github.com/withastro/astro/commit/97e2b6ad7a6fa23e82be28b2f57cdf3f85fab112), [`4af4d8fa0`](https://github.com/withastro/astro/commit/4af4d8fa0035130fbf31c82d72777c3679bc1ca5), [`f6add3924`](https://github.com/withastro/astro/commit/f6add3924d5cd59925a6ea4bf7f2f731709bc893), [`247eb7411`](https://github.com/withastro/astro/commit/247eb7411f429317e5cd7d401a6660ee73641313)]:
|
|
25
|
+
- astro@1.6.4
|
|
26
|
+
|
|
3
27
|
## 3.1.2
|
|
4
28
|
|
|
5
29
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -46,9 +46,9 @@ default `"advanced"`
|
|
|
46
46
|
|
|
47
47
|
Cloudflare Pages has 2 different modes for deploying functions, `advanced` mode which picks up the `_worker.js` in `dist`, or a directory mode where pages will compile the worker out of a functions folder in the project root.
|
|
48
48
|
|
|
49
|
-
For most projects the adaptor default of `advanced` will be
|
|
49
|
+
For most projects the adaptor default of `advanced` will be sufficient; the `dist` folder will contain your compiled project. Switching to directory mode allows you to use [pages plugins](https://developers.cloudflare.com/pages/platform/functions/plugins/) such as [Sentry](https://developers.cloudflare.com/pages/platform/functions/plugins/sentry/) or write custom code to enable logging.
|
|
50
50
|
|
|
51
|
-
In directory mode the adaptor will compile the client side part of you app the same way, but
|
|
51
|
+
In directory mode the adaptor will compile the client side part of you app the same way, but moves the worker script into a `functions` folder in the project root. The adaptor will only ever place a `[[path]].js` in that folder, allowing you to add additional plugins and pages middleware which can be checked into version control. Cloudflare documentation contains more information about [writing custom functions](https://developers.cloudflare.com/pages/platform/functions/).
|
|
52
52
|
|
|
53
53
|
```ts
|
|
54
54
|
// directory mode
|
|
@@ -92,16 +92,18 @@ To do this:
|
|
|
92
92
|
|
|
93
93
|
## Environment Variables
|
|
94
94
|
|
|
95
|
-
As Cloudflare Pages Functions [provides environment variables
|
|
95
|
+
As Cloudflare Pages Functions [provides environment variables per request](https://developers.cloudflare.com/pages/platform/functions/#adding-environment-variables-locally), you can only access private environment variables when a request has happened. Usually, this means moving environment variable access inside a function.
|
|
96
96
|
|
|
97
97
|
```js
|
|
98
|
-
//
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
98
|
+
// pages/[id].json.js
|
|
99
|
+
|
|
100
|
+
export function get({ params }) {
|
|
101
|
+
// Access environment variables per request inside a function
|
|
102
|
+
const serverUrl = import.meta.env.SERVER_URL;
|
|
103
|
+
const result = await fetch(serverUrl + "/user/" + params.id);
|
|
104
|
+
return {
|
|
105
|
+
body: await result.text(),
|
|
106
|
+
};
|
|
105
107
|
}
|
|
106
108
|
```
|
|
107
109
|
|
package/dist/server.advanced.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import "./shim.js";
|
|
2
1
|
import { App } from "astro/app";
|
|
2
|
+
import { getProcessEnvProxy } from "./util.js";
|
|
3
|
+
process.env = getProcessEnvProxy();
|
|
3
4
|
function createExports(manifest) {
|
|
4
5
|
const app = new App(manifest, false);
|
|
5
6
|
const fetch = async (request, env, context) => {
|
|
7
|
+
process.env = env;
|
|
6
8
|
const { origin, pathname } = new URL(request.url);
|
|
7
9
|
if (manifest.assets.has(pathname)) {
|
|
8
|
-
const assetRequest = new Request(`${origin}/static
|
|
10
|
+
const assetRequest = new Request(`${origin}/static/${app.removeBase(pathname)}`, request);
|
|
9
11
|
return env.ASSETS.fetch(assetRequest);
|
|
10
12
|
}
|
|
11
13
|
let routeData = app.match(request, { matchNotFound: true });
|
package/dist/server.directory.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import "./shim.js";
|
|
2
1
|
import { App } from "astro/app";
|
|
2
|
+
import { getProcessEnvProxy } from "./util.js";
|
|
3
|
+
process.env = getProcessEnvProxy();
|
|
3
4
|
function createExports(manifest) {
|
|
4
5
|
const app = new App(manifest, false);
|
|
5
6
|
const onRequest = async ({
|
|
@@ -7,9 +8,10 @@ function createExports(manifest) {
|
|
|
7
8
|
next,
|
|
8
9
|
...runtimeEnv
|
|
9
10
|
}) => {
|
|
11
|
+
process.env = runtimeEnv.env;
|
|
10
12
|
const { origin, pathname } = new URL(request.url);
|
|
11
13
|
if (manifest.assets.has(pathname)) {
|
|
12
|
-
const assetRequest = new Request(`${origin}/static
|
|
14
|
+
const assetRequest = new Request(`${origin}/static/${app.removeBase(pathname)}`, request);
|
|
13
15
|
return next(assetRequest);
|
|
14
16
|
}
|
|
15
17
|
let routeData = app.match(request, { matchNotFound: true });
|
package/dist/util.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getProcessEnvProxy(): {};
|
package/dist/util.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
function getProcessEnvProxy() {
|
|
2
|
+
return new Proxy(
|
|
3
|
+
{},
|
|
4
|
+
{
|
|
5
|
+
get: (target, prop) => {
|
|
6
|
+
console.warn(
|
|
7
|
+
`Unable to access \`import.meta\0.env.${prop.toString()}\` on initialization as the Cloudflare platform only provides the environment variables per request. Please move the environment variable access inside a function that's only called after a request has been received.`
|
|
8
|
+
);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
getProcessEnvProxy
|
|
15
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/cloudflare",
|
|
3
3
|
"description": "Deploy your site to cloudflare workers or cloudflare pages",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "4.0.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"author": "withastro",
|
|
@@ -30,9 +30,12 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"esbuild": "^0.14.42"
|
|
32
32
|
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"astro": "^1.6.5"
|
|
35
|
+
},
|
|
33
36
|
"devDependencies": {
|
|
34
|
-
"astro": "1.6.
|
|
35
|
-
"astro-scripts": "0.0.
|
|
37
|
+
"astro": "1.6.5",
|
|
38
|
+
"astro-scripts": "0.0.9",
|
|
36
39
|
"chai": "^4.3.6",
|
|
37
40
|
"cheerio": "^1.0.0-rc.11",
|
|
38
41
|
"mocha": "^9.2.2",
|
package/src/server.advanced.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import './shim.js';
|
|
2
|
-
|
|
3
1
|
import type { SSRManifest } from 'astro';
|
|
4
2
|
import { App } from 'astro/app';
|
|
3
|
+
import { getProcessEnvProxy } from './util.js';
|
|
4
|
+
|
|
5
|
+
process.env = getProcessEnvProxy();
|
|
5
6
|
|
|
6
7
|
type Env = {
|
|
7
8
|
ASSETS: { fetch: (req: Request) => Promise<Response> };
|
|
@@ -12,11 +13,13 @@ export function createExports(manifest: SSRManifest) {
|
|
|
12
13
|
const app = new App(manifest, false);
|
|
13
14
|
|
|
14
15
|
const fetch = async (request: Request, env: Env, context: any) => {
|
|
16
|
+
process.env = env as any;
|
|
17
|
+
|
|
15
18
|
const { origin, pathname } = new URL(request.url);
|
|
16
19
|
|
|
17
20
|
// static assets
|
|
18
21
|
if (manifest.assets.has(pathname)) {
|
|
19
|
-
const assetRequest = new Request(`${origin}/static
|
|
22
|
+
const assetRequest = new Request(`${origin}/static/${app.removeBase(pathname)}`, request);
|
|
20
23
|
return env.ASSETS.fetch(assetRequest);
|
|
21
24
|
}
|
|
22
25
|
|
package/src/server.directory.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import './shim.js';
|
|
2
|
-
|
|
3
1
|
import type { SSRManifest } from 'astro';
|
|
4
2
|
import { App } from 'astro/app';
|
|
3
|
+
import { getProcessEnvProxy } from './util.js';
|
|
4
|
+
|
|
5
|
+
process.env = getProcessEnvProxy();
|
|
5
6
|
|
|
6
7
|
export function createExports(manifest: SSRManifest) {
|
|
7
8
|
const app = new App(manifest, false);
|
|
@@ -14,10 +15,12 @@ export function createExports(manifest: SSRManifest) {
|
|
|
14
15
|
request: Request;
|
|
15
16
|
next: (request: Request) => void;
|
|
16
17
|
} & Record<string, unknown>) => {
|
|
18
|
+
process.env = runtimeEnv.env as any;
|
|
19
|
+
|
|
17
20
|
const { origin, pathname } = new URL(request.url);
|
|
18
21
|
// static assets
|
|
19
22
|
if (manifest.assets.has(pathname)) {
|
|
20
|
-
const assetRequest = new Request(`${origin}/static
|
|
23
|
+
const assetRequest = new Request(`${origin}/static/${app.removeBase(pathname)}`, request);
|
|
21
24
|
return next(assetRequest);
|
|
22
25
|
}
|
|
23
26
|
|
package/src/util.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export function getProcessEnvProxy() {
|
|
2
|
+
return new Proxy(
|
|
3
|
+
{},
|
|
4
|
+
{
|
|
5
|
+
get: (target, prop) => {
|
|
6
|
+
console.warn(
|
|
7
|
+
// NOTE: \0 prevents Vite replacement
|
|
8
|
+
`Unable to access \`import.meta\0.env.${prop.toString()}\` on initialization ` +
|
|
9
|
+
`as the Cloudflare platform only provides the environment variables per request. ` +
|
|
10
|
+
`Please move the environment variable access inside a function ` +
|
|
11
|
+
`that's only called after a request has been received.`
|
|
12
|
+
);
|
|
13
|
+
},
|
|
14
|
+
}
|
|
15
|
+
);
|
|
16
|
+
}
|
package/test/basics.test.js
CHANGED
package/dist/shim.d.ts
DELETED
|
File without changes
|
package/dist/shim.js
DELETED
package/src/shim.ts
DELETED