@astrojs/cloudflare 11.0.1 → 11.0.3

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.
@@ -1 +1,3 @@
1
- export {};
1
+ import type { APIRoute } from 'astro';
2
+ export declare const prerender = false;
3
+ export declare const GET: APIRoute;
@@ -1,3 +1,11 @@
1
- export {};
2
- // NOTE: this file is empty on purpose
3
- // it allows use to offer `imageService: 'compile'`
1
+ export const prerender = false;
2
+ export const GET = (ctx) => {
3
+ const href = ctx.url.searchParams.get('href');
4
+ if (!href) {
5
+ return new Response("Missing 'href' query parameter", {
6
+ status: 400,
7
+ statusText: "Missing 'href' query parameter",
8
+ });
9
+ }
10
+ return fetch(new URL(href, ctx.url.origin));
11
+ };
@@ -0,0 +1,2 @@
1
+ import type { MiddlewareHandler } from 'astro';
2
+ export declare const onRequest: MiddlewareHandler;
@@ -0,0 +1,18 @@
1
+ import { When, whenAmI } from '@it-astro:when';
2
+ const middlewares = {
3
+ [When.Client]: () => {
4
+ throw new Error('Client should not run a middleware!');
5
+ },
6
+ [When.DevServer]: (_, next) => next(),
7
+ [When.Server]: (_, next) => next(),
8
+ [When.Prerender]: (ctx, next) => {
9
+ if (ctx.locals.runtime === undefined) {
10
+ ctx.locals.runtime = {
11
+ env: process.env,
12
+ };
13
+ }
14
+ return next();
15
+ },
16
+ [When.StaticBuild]: (_, next) => next(),
17
+ };
18
+ export const onRequest = middlewares[whenAmI];
package/dist/index.js CHANGED
@@ -3,6 +3,7 @@ import { appendFile, rename, stat } from 'node:fs/promises';
3
3
  import { createInterface } from 'node:readline/promises';
4
4
  import { appendForwardSlash, prependForwardSlash, removeLeadingForwardSlash, } from '@astrojs/internal-helpers/path';
5
5
  import { createRedirectsFromAstroRoutes } from '@astrojs/underscore-redirects';
6
+ import astroWhen from '@inox-tools/astro-when';
6
7
  import { AstroError } from 'astro/errors';
7
8
  import { getPlatformProxy } from 'wrangler';
8
9
  import { cloudflareModuleLoader, } from './utils/cloudflare-module-loader.js';
@@ -36,7 +37,7 @@ export default function createIntegration(args) {
36
37
  return {
37
38
  name: '@astrojs/cloudflare',
38
39
  hooks: {
39
- 'astro:config:setup': ({ command, config, updateConfig, logger, addWatchFile }) => {
40
+ 'astro:config:setup': ({ command, config, updateConfig, logger, addWatchFile, addMiddleware, }) => {
40
41
  updateConfig({
41
42
  build: {
42
43
  client: new URL(`.${wrapWithSlashes(config.base)}`, config.outDir),
@@ -51,10 +52,15 @@ export default function createIntegration(args) {
51
52
  cloudflareModulePlugin,
52
53
  ],
53
54
  },
55
+ integrations: [astroWhen()],
54
56
  image: setImageConfig(args?.imageService ?? 'compile', config.image, command, logger),
55
57
  });
56
58
  addWatchFile(new URL('./wrangler.toml', config.root));
57
59
  addWatchFile(new URL('./wrangler.json', config.root));
60
+ addMiddleware({
61
+ entrypoint: '@astrojs/cloudflare/entrypoints/middleware.js',
62
+ order: 'pre',
63
+ });
58
64
  },
59
65
  'astro:config:done': ({ setAdapter, config }) => {
60
66
  if (config.output === 'static') {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@astrojs/cloudflare",
3
3
  "description": "Deploy your site to Cloudflare Workers/Pages",
4
- "version": "11.0.1",
4
+ "version": "11.0.3",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",
7
7
  "author": "withastro",
@@ -20,6 +20,7 @@
20
20
  "exports": {
21
21
  ".": "./dist/index.js",
22
22
  "./entrypoints/server.js": "./dist/entrypoints/server.js",
23
+ "./entrypoints/middleware.js": "./dist/entrypoints/middleware.js",
23
24
  "./image-service": "./dist/entrypoints/image-service.js",
24
25
  "./image-endpoint": "./dist/entrypoints/image-endpoint.js",
25
26
  "./package.json": "./package.json"
@@ -28,27 +29,28 @@
28
29
  "dist"
29
30
  ],
30
31
  "dependencies": {
31
- "@astrojs/internal-helpers": "0.3.0",
32
- "@astrojs/underscore-redirects": "^0.3.3",
33
- "@cloudflare/workers-types": "^4.20240320.1",
34
- "esbuild": "^0.19.5",
32
+ "@astrojs/internal-helpers": "0.4.1",
33
+ "@astrojs/underscore-redirects": "^0.3.4",
34
+ "@cloudflare/workers-types": "^4.20240620.0",
35
+ "esbuild": "^0.22.0",
35
36
  "estree-walker": "^3.0.3",
36
37
  "magic-string": "^0.30.10",
37
- "miniflare": "^3.20240320.0",
38
+ "miniflare": "^3.20240620.0",
38
39
  "tiny-glob": "^0.2.9",
39
- "wrangler": "^3.39.0"
40
+ "wrangler": "^3.62.0",
41
+ "@inox-tools/astro-when": "^0.2.0"
40
42
  },
41
43
  "peerDependencies": {
42
44
  "astro": "^4.10.3"
43
45
  },
44
46
  "devDependencies": {
45
- "astro": "^4.10.3",
47
+ "astro": "^4.11.3",
46
48
  "cheerio": "1.0.0-rc.12",
47
49
  "execa": "^8.0.1",
48
50
  "fast-glob": "^3.3.2",
49
- "rollup": "^4.14.0",
51
+ "rollup": "^4.18.0",
50
52
  "strip-ansi": "^7.1.0",
51
- "vite": "^5.2.13",
53
+ "vite": "^5.3.2",
52
54
  "@astrojs/test-utils": "0.0.1",
53
55
  "astro-scripts": "0.0.14"
54
56
  },