@astrojs/cloudflare 4.0.0 → 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 +9 -0
- package/README.md +10 -8
- package/dist/server.advanced.d.ts +0 -1
- package/dist/server.advanced.js +3 -1
- package/dist/server.directory.d.ts +0 -1
- package/dist/server.directory.js +3 -1
- package/dist/util.d.ts +1 -0
- package/dist/util.js +15 -0
- package/package.json +3 -3
- package/src/server.advanced.ts +5 -2
- package/src/server.directory.ts +5 -2
- 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,14 @@
|
|
|
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
|
+
|
|
3
12
|
## 4.0.0
|
|
4
13
|
|
|
5
14
|
### Major Changes
|
package/README.md
CHANGED
|
@@ -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,8 +1,10 @@
|
|
|
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
10
|
const assetRequest = new Request(`${origin}/static/${app.removeBase(pathname)}`, request);
|
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,6 +8,7 @@ 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
14
|
const assetRequest = new Request(`${origin}/static/${app.removeBase(pathname)}`, request);
|
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.0.
|
|
4
|
+
"version": "4.0.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"author": "withastro",
|
|
@@ -31,10 +31,10 @@
|
|
|
31
31
|
"esbuild": "^0.14.42"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"astro": "^1.6.
|
|
34
|
+
"astro": "^1.6.5"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"astro": "1.6.
|
|
37
|
+
"astro": "1.6.5",
|
|
38
38
|
"astro-scripts": "0.0.9",
|
|
39
39
|
"chai": "^4.3.6",
|
|
40
40
|
"cheerio": "^1.0.0-rc.11",
|
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,6 +13,8 @@ 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
|
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,6 +15,8 @@ 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)) {
|
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