@astrojs/cloudflare 12.2.0 → 12.2.2
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/LICENSE +59 -0
- package/dist/entrypoints/image-endpoint.js +14 -10
- package/dist/entrypoints/image-service.js +32 -33
- package/dist/entrypoints/middleware.js +10 -8
- package/dist/entrypoints/server.js +57 -48
- package/dist/index.js +255 -250
- package/dist/utils/assets.js +62 -60
- package/dist/utils/cloudflare-module-loader.js +164 -192
- package/dist/utils/env.js +12 -10
- package/dist/utils/generate-routes-json.js +212 -247
- package/dist/utils/image-config.js +32 -29
- package/dist/utils/non-server-chunk-detector.js +48 -65
- package/package.json +13 -15
package/LICENSE
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
This license applies to parts of the `packages/create-astro` and `packages/astro` subdirectories originating from the https://github.com/sveltejs/kit repository:
|
|
25
|
+
|
|
26
|
+
Copyright (c) 2020 [these people](https://github.com/sveltejs/kit/graphs/contributors)
|
|
27
|
+
|
|
28
|
+
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:
|
|
29
|
+
|
|
30
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
31
|
+
|
|
32
|
+
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.
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
"""
|
|
36
|
+
This license applies to parts of the `packages/create-astro` and `packages/astro` subdirectories originating from the https://github.com/vitejs/vite repository:
|
|
37
|
+
|
|
38
|
+
MIT License
|
|
39
|
+
|
|
40
|
+
Copyright (c) 2019-present, Yuxi (Evan) You and Vite contributors
|
|
41
|
+
|
|
42
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
43
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
44
|
+
in the Software without restriction, including without limitation the rights
|
|
45
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
46
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
47
|
+
furnished to do so, subject to the following conditions:
|
|
48
|
+
|
|
49
|
+
The above copyright notice and this permission notice shall be included in all
|
|
50
|
+
copies or substantial portions of the Software.
|
|
51
|
+
|
|
52
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
53
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
54
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
55
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
56
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
57
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
58
|
+
SOFTWARE.
|
|
59
|
+
"""
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
const prerender = false;
|
|
2
|
+
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
|
+
};
|
|
12
|
+
export {
|
|
13
|
+
GET,
|
|
14
|
+
prerender
|
|
11
15
|
};
|
|
@@ -1,35 +1,34 @@
|
|
|
1
|
-
import { joinPaths } from
|
|
2
|
-
import { baseService } from
|
|
3
|
-
import { isESMImportedImage, isRemoteAllowed } from
|
|
1
|
+
import { joinPaths } from "@astrojs/internal-helpers/path";
|
|
2
|
+
import { baseService } from "astro/assets";
|
|
3
|
+
import { isESMImportedImage, isRemoteAllowed } from "../utils/assets.js";
|
|
4
4
|
const service = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
5
|
+
...baseService,
|
|
6
|
+
getURL: (options, imageConfig) => {
|
|
7
|
+
const resizingParams = ["onerror=redirect"];
|
|
8
|
+
if (options.width) resizingParams.push(`width=${options.width}`);
|
|
9
|
+
if (options.height) resizingParams.push(`height=${options.height}`);
|
|
10
|
+
if (options.quality) resizingParams.push(`quality=${options.quality}`);
|
|
11
|
+
if (options.fit) resizingParams.push(`fit=${options.fit}`);
|
|
12
|
+
if (options.format) resizingParams.push(`format=${options.format}`);
|
|
13
|
+
let imageSource = "";
|
|
14
|
+
if (isESMImportedImage(options.src)) {
|
|
15
|
+
imageSource = options.src.src;
|
|
16
|
+
} else if (isRemoteAllowed(options.src, imageConfig)) {
|
|
17
|
+
imageSource = options.src;
|
|
18
|
+
} else {
|
|
19
|
+
return options.src;
|
|
20
|
+
}
|
|
21
|
+
const imageEndpoint = joinPaths(
|
|
22
|
+
// @ts-expect-error Can't recognise import.meta.env
|
|
23
|
+
import.meta.env.BASE_URL,
|
|
24
|
+
"/cdn-cgi/image",
|
|
25
|
+
resizingParams.join(","),
|
|
26
|
+
imageSource
|
|
27
|
+
);
|
|
28
|
+
return imageEndpoint;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
var image_service_default = service;
|
|
32
|
+
export {
|
|
33
|
+
image_service_default as default
|
|
34
34
|
};
|
|
35
|
-
export default service;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
const onRequest = (context, next) => {
|
|
2
|
+
if (context.isPrerendered) {
|
|
3
|
+
context.locals.runtime ??= {
|
|
4
|
+
env: process.env
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
return next();
|
|
8
|
+
};
|
|
9
|
+
export {
|
|
10
|
+
onRequest
|
|
9
11
|
};
|
|
@@ -1,51 +1,60 @@
|
|
|
1
|
-
import { App } from
|
|
2
|
-
import { setGetEnv } from
|
|
3
|
-
import { createGetEnv } from
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { App } from "astro/app";
|
|
2
|
+
import { setGetEnv } from "astro/env/setup";
|
|
3
|
+
import { createGetEnv } from "../utils/env.js";
|
|
4
|
+
function createExports(manifest) {
|
|
5
|
+
const app = new App(manifest);
|
|
6
|
+
const fetch = async (request, env, context) => {
|
|
7
|
+
const { pathname } = new URL(request.url);
|
|
8
|
+
if (manifest.assets.has(pathname)) {
|
|
9
|
+
return env.ASSETS.fetch(request.url.replace(/\.html$/, ""));
|
|
10
|
+
}
|
|
11
|
+
const routeData = app.match(request);
|
|
12
|
+
if (!routeData) {
|
|
13
|
+
const asset = await env.ASSETS.fetch(
|
|
14
|
+
request.url.replace(/index.html$/, "").replace(/\.html$/, "")
|
|
15
|
+
);
|
|
16
|
+
if (asset.status !== 404) {
|
|
17
|
+
return asset;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
Reflect.set(
|
|
21
|
+
request,
|
|
22
|
+
Symbol.for("astro.clientAddress"),
|
|
23
|
+
request.headers.get("cf-connecting-ip")
|
|
24
|
+
);
|
|
25
|
+
process.env.ASTRO_STUDIO_APP_TOKEN ??= (() => {
|
|
26
|
+
if (typeof env.ASTRO_STUDIO_APP_TOKEN === "string") {
|
|
27
|
+
return env.ASTRO_STUDIO_APP_TOKEN;
|
|
28
|
+
}
|
|
29
|
+
})();
|
|
30
|
+
const locals = {
|
|
31
|
+
runtime: {
|
|
32
|
+
env,
|
|
33
|
+
cf: request.cf,
|
|
34
|
+
caches,
|
|
35
|
+
ctx: {
|
|
36
|
+
waitUntil: (promise) => context.waitUntil(promise),
|
|
37
|
+
// Currently not available: https://developers.cloudflare.com/pages/platform/known-issues/#pages-functions
|
|
38
|
+
passThroughOnException: () => {
|
|
39
|
+
throw new Error(
|
|
40
|
+
"`passThroughOnException` is currently not available in Cloudflare Pages. See https://developers.cloudflare.com/pages/platform/known-issues/#pages-functions."
|
|
41
|
+
);
|
|
42
|
+
},
|
|
43
|
+
props: {}
|
|
11
44
|
}
|
|
12
|
-
|
|
13
|
-
if (!routeData) {
|
|
14
|
-
// https://developers.cloudflare.com/pages/functions/api-reference/#envassetsfetch
|
|
15
|
-
const asset = await env.ASSETS.fetch(request.url.replace(/index.html$/, '').replace(/\.html$/, ''));
|
|
16
|
-
if (asset.status !== 404) {
|
|
17
|
-
return asset;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
Reflect.set(request, Symbol.for('astro.clientAddress'), request.headers.get('cf-connecting-ip'));
|
|
21
|
-
process.env.ASTRO_STUDIO_APP_TOKEN ??= (() => {
|
|
22
|
-
if (typeof env.ASTRO_STUDIO_APP_TOKEN === 'string') {
|
|
23
|
-
return env.ASTRO_STUDIO_APP_TOKEN;
|
|
24
|
-
}
|
|
25
|
-
})();
|
|
26
|
-
const locals = {
|
|
27
|
-
runtime: {
|
|
28
|
-
env: env,
|
|
29
|
-
cf: request.cf,
|
|
30
|
-
caches: caches,
|
|
31
|
-
ctx: {
|
|
32
|
-
waitUntil: (promise) => context.waitUntil(promise),
|
|
33
|
-
// Currently not available: https://developers.cloudflare.com/pages/platform/known-issues/#pages-functions
|
|
34
|
-
passThroughOnException: () => {
|
|
35
|
-
throw new Error('`passThroughOnException` is currently not available in Cloudflare Pages. See https://developers.cloudflare.com/pages/platform/known-issues/#pages-functions.');
|
|
36
|
-
},
|
|
37
|
-
props: {},
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
};
|
|
41
|
-
setGetEnv(createGetEnv(env));
|
|
42
|
-
const response = await app.render(request, { routeData, locals });
|
|
43
|
-
if (app.setCookieHeaders) {
|
|
44
|
-
for (const setCookieHeader of app.setCookieHeaders(response)) {
|
|
45
|
-
response.headers.append('Set-Cookie', setCookieHeader);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return response;
|
|
45
|
+
}
|
|
49
46
|
};
|
|
50
|
-
|
|
47
|
+
setGetEnv(createGetEnv(env));
|
|
48
|
+
const response = await app.render(request, { routeData, locals });
|
|
49
|
+
if (app.setCookieHeaders) {
|
|
50
|
+
for (const setCookieHeader of app.setCookieHeaders(response)) {
|
|
51
|
+
response.headers.append("Set-Cookie", setCookieHeader);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return response;
|
|
55
|
+
};
|
|
56
|
+
return { default: { fetch } };
|
|
51
57
|
}
|
|
58
|
+
export {
|
|
59
|
+
createExports
|
|
60
|
+
};
|