@astrojs/cloudflare 0.0.0-rc-20220721064837

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.
@@ -0,0 +1,5 @@
1
+ @astrojs/cloudflare:build: cache hit, replaying output e2e204dcfcd37c6d
2
+ @astrojs/cloudflare:build: 
3
+ @astrojs/cloudflare:build: > @astrojs/cloudflare@0.2.4 build /Users/fks/Code/astro/packages/integrations/cloudflare
4
+ @astrojs/cloudflare:build: > astro-scripts build "src/**/*.ts" && tsc
5
+ @astrojs/cloudflare:build: 
package/CHANGELOG.md ADDED
@@ -0,0 +1,45 @@
1
+ # @astrojs/cloudflare
2
+
3
+ ## 0.0.0-rc-20220721064837
4
+
5
+ ### Minor Changes
6
+
7
+ - [#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
8
+
9
+ The new `Astro.clientAddress` property allows you to get the IP address of the requested user.
10
+
11
+ ```astro
12
+ <div>Your address { Astro.clientAddress }</div>
13
+ ```
14
+
15
+ 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.
16
+
17
+ ## 0.2.4
18
+
19
+ ### Patch Changes
20
+
21
+ - [#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
22
+
23
+ ## 0.2.3
24
+
25
+ ### Patch Changes
26
+
27
+ - [#3854](https://github.com/withastro/astro/pull/3854) [`b012ee55`](https://github.com/withastro/astro/commit/b012ee55b107dea0730286263b27d83e530fad5d) Thanks [@bholmesdev](https://github.com/bholmesdev)! - [astro add] Support adapters and third party packages
28
+
29
+ ## 0.2.2
30
+
31
+ ### Patch Changes
32
+
33
+ - [#3777](https://github.com/withastro/astro/pull/3777) [`976e1f17`](https://github.com/withastro/astro/commit/976e1f175a95ea39f737b8575e4fdf3c3d89e1ee) Thanks [@tony-sull](https://github.com/tony-sull)! - Disables HTTP streaming in Cloudflare Pages deployments
34
+
35
+ ## 0.2.1
36
+
37
+ ### Patch Changes
38
+
39
+ - [#3695](https://github.com/withastro/astro/pull/3695) [`0d667d0e`](https://github.com/withastro/astro/commit/0d667d0e572d76d4c819816ddf51ed14b43e2551) Thanks [@nrgnrg](https://github.com/nrgnrg)! - fix custom 404 pages not rendering
40
+
41
+ ## 0.2.0
42
+
43
+ ### Minor Changes
44
+
45
+ - [#3600](https://github.com/withastro/astro/pull/3600) [`7f423581`](https://github.com/withastro/astro/commit/7f423581411648c9a69b68918ff930581f12cf16) Thanks [@nrgnrg](https://github.com/nrgnrg)! - add SSR adaptor for Cloudflare Pages functions
package/LICENSE ADDED
@@ -0,0 +1,61 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Fred K. Schott
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+
24
+ """
25
+ This license applies to parts of the `packages/create-astro` and `packages/astro` subdirectories originating from the https://github.com/sveltejs/kit repository:
26
+
27
+ Copyright (c) 2020 [these people](https://github.com/sveltejs/kit/graphs/contributors)
28
+
29
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
30
+
31
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
32
+
33
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34
+ """
35
+
36
+
37
+ """
38
+ This license applies to parts of the `packages/create-astro` and `packages/astro` subdirectories originating from the https://github.com/vitejs/vite repository:
39
+
40
+ MIT License
41
+
42
+ Copyright (c) 2019-present, Yuxi (Evan) You and Vite contributors
43
+
44
+ Permission is hereby granted, free of charge, to any person obtaining a copy
45
+ of this software and associated documentation files (the "Software"), to deal
46
+ in the Software without restriction, including without limitation the rights
47
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
48
+ copies of the Software, and to permit persons to whom the Software is
49
+ furnished to do so, subject to the following conditions:
50
+
51
+ The above copyright notice and this permission notice shall be included in all
52
+ copies or substantial portions of the Software.
53
+
54
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
55
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
56
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
57
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
58
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
59
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
60
+ SOFTWARE.
61
+ """
package/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # @astrojs/cloudflare
2
+
3
+ An SSR adapter for use with Cloudflare Pages Functions targets. Write your code in Astro/Node and deploy to Cloudflare Pages.
4
+
5
+ In your `astro.config.mjs` use:
6
+
7
+ ```js
8
+ import { defineConfig } from 'astro/config';
9
+ import cloudflare from '@astrojs/cloudflare';
10
+
11
+ export default defineConfig({
12
+ adapter: cloudflare()
13
+ });
14
+ ```
15
+
16
+ ## Enabling Preview
17
+
18
+ In order for preview to work you must install `wrangler`
19
+
20
+ ```sh
21
+ $ pnpm install wrangler --save-dev
22
+ ```
23
+
24
+ It's then possible to update the preview script in your `package.json` to `"preview": "wrangler pages dev ./dist"`
25
+
26
+ ## Streams
27
+
28
+ Some integrations such as [React](https://github.com/withastro/astro/tree/main/packages/integrations/react) rely on web streams. Currently Cloudflare Pages functions are in beta and don't support the `streams_enable_constructors` feature flag.
29
+
30
+ In order to work around this:
31
+ - install the `"web-streams-polyfill"` package
32
+ - add `import "web-streams-polyfill/es2018";` to the top of the front matter of every page which requires streams, such as server rendering a React component.
@@ -0,0 +1,3 @@
1
+ import type { AstroAdapter, AstroIntegration } from 'astro';
2
+ export declare function getAdapter(): AstroAdapter;
3
+ export default function createIntegration(): AstroIntegration;
package/dist/index.js ADDED
@@ -0,0 +1,67 @@
1
+ import esbuild from "esbuild";
2
+ import * as fs from "fs";
3
+ import { fileURLToPath } from "url";
4
+ function getAdapter() {
5
+ return {
6
+ name: "@astrojs/cloudflare",
7
+ serverEntrypoint: "@astrojs/cloudflare/server.js",
8
+ exports: ["default"]
9
+ };
10
+ }
11
+ function createIntegration() {
12
+ let _config;
13
+ let _buildConfig;
14
+ return {
15
+ name: "@astrojs/cloudflare",
16
+ hooks: {
17
+ "astro:config:done": ({ setAdapter, config }) => {
18
+ setAdapter(getAdapter());
19
+ _config = config;
20
+ },
21
+ "astro:build:start": ({ buildConfig }) => {
22
+ _buildConfig = buildConfig;
23
+ buildConfig.serverEntry = "_worker.js";
24
+ buildConfig.client = new URL("./static/", _config.outDir);
25
+ buildConfig.server = new URL("./", _config.outDir);
26
+ },
27
+ "astro:build:setup": ({ vite, target }) => {
28
+ if (target === "server") {
29
+ vite.resolve = vite.resolve || {};
30
+ vite.resolve.alias = vite.resolve.alias || {};
31
+ const aliases = [{ find: "react-dom/server", replacement: "react-dom/server.browser" }];
32
+ if (Array.isArray(vite.resolve.alias)) {
33
+ vite.resolve.alias = [...vite.resolve.alias, ...aliases];
34
+ } else {
35
+ for (const alias of aliases) {
36
+ vite.resolve.alias[alias.find] = alias.replacement;
37
+ }
38
+ }
39
+ vite.ssr = {
40
+ target: "webworker",
41
+ noExternal: true
42
+ };
43
+ }
44
+ },
45
+ "astro:build:done": async () => {
46
+ const entryUrl = new URL(_buildConfig.serverEntry, _buildConfig.server);
47
+ const pkg = fileURLToPath(entryUrl);
48
+ await esbuild.build({
49
+ target: "es2020",
50
+ platform: "browser",
51
+ entryPoints: [pkg],
52
+ outfile: pkg,
53
+ allowOverwrite: true,
54
+ format: "esm",
55
+ bundle: true,
56
+ minify: true
57
+ });
58
+ const chunksUrl = new URL("./chunks", _buildConfig.server);
59
+ await fs.promises.rm(chunksUrl, { recursive: true, force: true });
60
+ }
61
+ }
62
+ };
63
+ }
64
+ export {
65
+ createIntegration as default,
66
+ getAdapter
67
+ };
@@ -0,0 +1,13 @@
1
+ import './shim.js';
2
+ import type { SSRManifest } from 'astro';
3
+ declare type Env = {
4
+ ASSETS: {
5
+ fetch: (req: Request) => Promise<Response>;
6
+ };
7
+ };
8
+ export declare function createExports(manifest: SSRManifest): {
9
+ default: {
10
+ fetch: (request: Request, env: Env) => Promise<Response>;
11
+ };
12
+ };
13
+ export {};
package/dist/server.js ADDED
@@ -0,0 +1,28 @@
1
+ import "./shim.js";
2
+ import { App } from "astro/app";
3
+ function createExports(manifest) {
4
+ const app = new App(manifest, false);
5
+ const fetch = async (request, env) => {
6
+ const { origin, pathname } = new URL(request.url);
7
+ if (manifest.assets.has(pathname)) {
8
+ const assetRequest = new Request(`${origin}/static${pathname}`, request);
9
+ return env.ASSETS.fetch(assetRequest);
10
+ }
11
+ if (app.match(request)) {
12
+ Reflect.set(request, Symbol.for("astro.clientAddress"), request.headers.get("cf-connecting-ip"));
13
+ return app.render(request);
14
+ }
15
+ const _404Request = new Request(`${origin}/404`, request);
16
+ if (app.match(_404Request)) {
17
+ return app.render(_404Request);
18
+ }
19
+ return new Response(null, {
20
+ status: 404,
21
+ statusText: "Not found"
22
+ });
23
+ };
24
+ return { default: { fetch } };
25
+ }
26
+ export {
27
+ createExports
28
+ };
package/dist/shim.d.ts ADDED
File without changes
package/dist/shim.js ADDED
@@ -0,0 +1,4 @@
1
+ globalThis.process = {
2
+ argv: [],
3
+ env: {}
4
+ };
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@astrojs/cloudflare",
3
+ "description": "Deploy your site to cloudflare pages functions",
4
+ "version": "0.0.0-rc-20220721064837",
5
+ "type": "module",
6
+ "types": "./dist/index.d.ts",
7
+ "author": "withastro",
8
+ "license": "MIT",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/withastro/astro.git",
12
+ "directory": "packages/integrations/cloudflare"
13
+ },
14
+ "keywords": [
15
+ "astro-adapter"
16
+ ],
17
+ "bugs": "https://github.com/withastro/astro/issues",
18
+ "homepage": "https://docs.astro.build/en/guides/integrations-guide/cloudflare/",
19
+ "exports": {
20
+ ".": "./dist/index.js",
21
+ "./server.js": "./dist/server.js",
22
+ "./package.json": "./package.json"
23
+ },
24
+ "dependencies": {
25
+ "esbuild": "^0.14.42"
26
+ },
27
+ "devDependencies": {
28
+ "astro": "0.0.0-rc-20220721064837",
29
+ "astro-scripts": "0.0.6"
30
+ },
31
+ "scripts": {
32
+ "build": "astro-scripts build \"src/**/*.ts\" && tsc",
33
+ "build:ci": "astro-scripts build \"src/**/*.ts\"",
34
+ "dev": "astro-scripts dev \"src/**/*.ts\""
35
+ }
36
+ }
package/src/index.ts ADDED
@@ -0,0 +1,73 @@
1
+ import type { AstroAdapter, AstroConfig, AstroIntegration, BuildConfig } from 'astro';
2
+ import esbuild from 'esbuild';
3
+ import * as fs from 'fs';
4
+ import { fileURLToPath } from 'url';
5
+
6
+ export function getAdapter(): AstroAdapter {
7
+ return {
8
+ name: '@astrojs/cloudflare',
9
+ serverEntrypoint: '@astrojs/cloudflare/server.js',
10
+ exports: ['default'],
11
+ };
12
+ }
13
+
14
+ export default function createIntegration(): AstroIntegration {
15
+ let _config: AstroConfig;
16
+ let _buildConfig: BuildConfig;
17
+
18
+ return {
19
+ name: '@astrojs/cloudflare',
20
+ hooks: {
21
+ 'astro:config:done': ({ setAdapter, config }) => {
22
+ setAdapter(getAdapter());
23
+ _config = config;
24
+ },
25
+ 'astro:build:start': ({ buildConfig }) => {
26
+ _buildConfig = buildConfig;
27
+ buildConfig.serverEntry = '_worker.js';
28
+ buildConfig.client = new URL('./static/', _config.outDir);
29
+ buildConfig.server = new URL('./', _config.outDir);
30
+ },
31
+ 'astro:build:setup': ({ vite, target }) => {
32
+ if (target === 'server') {
33
+ vite.resolve = vite.resolve || {};
34
+ vite.resolve.alias = vite.resolve.alias || {};
35
+
36
+ const aliases = [{ find: 'react-dom/server', replacement: 'react-dom/server.browser' }];
37
+
38
+ if (Array.isArray(vite.resolve.alias)) {
39
+ vite.resolve.alias = [...vite.resolve.alias, ...aliases];
40
+ } else {
41
+ for (const alias of aliases) {
42
+ (vite.resolve.alias as Record<string, string>)[alias.find] = alias.replacement;
43
+ }
44
+ }
45
+
46
+ vite.ssr = {
47
+ target: 'webworker',
48
+ noExternal: true,
49
+ };
50
+ }
51
+ },
52
+ 'astro:build:done': async () => {
53
+ const entryUrl = new URL(_buildConfig.serverEntry, _buildConfig.server);
54
+ const pkg = fileURLToPath(entryUrl);
55
+
56
+ await esbuild.build({
57
+ target: 'es2020',
58
+ platform: 'browser',
59
+ entryPoints: [pkg],
60
+ outfile: pkg,
61
+ allowOverwrite: true,
62
+ format: 'esm',
63
+ bundle: true,
64
+ minify: true,
65
+ });
66
+
67
+ // throw the server folder in the bin
68
+ const chunksUrl = new URL('./chunks', _buildConfig.server);
69
+ await fs.promises.rm(chunksUrl, { recursive: true, force: true });
70
+ },
71
+ },
72
+ };
73
+ }
package/src/server.ts ADDED
@@ -0,0 +1,44 @@
1
+ import './shim.js';
2
+
3
+ import type { SSRManifest } from 'astro';
4
+ import { App } from 'astro/app';
5
+
6
+ type Env = {
7
+ ASSETS: { fetch: (req: Request) => Promise<Response> };
8
+ };
9
+
10
+ export function createExports(manifest: SSRManifest) {
11
+ const app = new App(manifest, false);
12
+
13
+ const fetch = async (request: Request, env: Env) => {
14
+ const { origin, pathname } = new URL(request.url);
15
+
16
+ // static assets
17
+ if (manifest.assets.has(pathname)) {
18
+ const assetRequest = new Request(`${origin}/static${pathname}`, request);
19
+ return env.ASSETS.fetch(assetRequest);
20
+ }
21
+
22
+ if (app.match(request)) {
23
+ Reflect.set(
24
+ request,
25
+ Symbol.for('astro.clientAddress'),
26
+ request.headers.get('cf-connecting-ip')
27
+ );
28
+ return app.render(request);
29
+ }
30
+
31
+ // 404
32
+ const _404Request = new Request(`${origin}/404`, request);
33
+ if (app.match(_404Request)) {
34
+ return app.render(_404Request);
35
+ }
36
+
37
+ return new Response(null, {
38
+ status: 404,
39
+ statusText: 'Not found',
40
+ });
41
+ };
42
+
43
+ return { default: { fetch } };
44
+ }
package/src/shim.ts ADDED
@@ -0,0 +1,4 @@
1
+ (globalThis as any).process = {
2
+ argv: [],
3
+ env: {},
4
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "../../../tsconfig.base.json",
3
+ "include": ["src"],
4
+ "compilerOptions": {
5
+ "allowJs": true,
6
+ "module": "ES2020",
7
+ "outDir": "./dist",
8
+ "target": "ES2020"
9
+ }
10
+ }