@bleedingdev/modern-js-app-tools 3.5.0-ultramodern.3 → 3.5.0-ultramodern.31
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/dist/cjs/builder/generator/getBuilderEnvironments.js +1 -0
- package/dist/cjs/index.js +50 -44
- package/dist/cjs/plugins/backend-federation/codegen.js +208 -0
- package/dist/cjs/plugins/backend-federation/config.js +217 -0
- package/dist/cjs/plugins/backend-federation/emit.js +139 -0
- package/dist/cjs/plugins/backendFederationBuild.js +53 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare/artifacts.js +127 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare/constants.js +137 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare/delivery-unit.js +118 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare/i18n-worker.js +135 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare/index.js +126 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare/security-policies.js +223 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare/types.js +18 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare/utils.js +66 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare/worker-manifest.js +178 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare/wrangler-config.js +189 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare-output-contract.js +91 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare-output-plan.js +93 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/identity.js +83 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/index.js +184 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/issues.js +54 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/manifest.js +83 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/mutation-policy.js +158 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/worker-bundles.js +137 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier.js +62 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare.js +2 -502
- package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.001-bootstrap-security.mjs +22 -0
- package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.002-assets-routes.mjs +0 -0
- package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.003-i18n-locales.mjs +0 -0
- package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.004-rendering-css.mjs +0 -0
- package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.005-worker-dispatch.mjs +0 -0
- package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.006-fetch-handler.mjs +32 -0
- package/dist/esm/builder/generator/getBuilderEnvironments.mjs +1 -0
- package/dist/esm/index.mjs +2 -0
- package/dist/esm/plugins/backend-federation/codegen.mjs +157 -0
- package/dist/esm/plugins/backend-federation/config.mjs +141 -0
- package/dist/esm/plugins/backend-federation/emit.mjs +88 -0
- package/dist/esm/plugins/backendFederationBuild.mjs +1 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare/artifacts.mjs +64 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare/constants.mjs +33 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare/delivery-unit.mjs +67 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare/i18n-worker.mjs +97 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare/index.mjs +78 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare/security-policies.mjs +167 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare/types.mjs +0 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare/utils.mjs +12 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare/worker-manifest.mjs +118 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare/wrangler-config.mjs +135 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare-output-contract.mjs +17 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare-output-plan.mjs +45 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/identity.mjs +45 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/index.mjs +129 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/issues.mjs +10 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/manifest.mjs +45 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/mutation-policy.mjs +97 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/worker-bundles.mjs +68 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier.mjs +1 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare.mjs +1 -492
- package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.001-bootstrap-security.mjs +22 -0
- package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.002-assets-routes.mjs +0 -0
- package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.003-i18n-locales.mjs +0 -0
- package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.004-rendering-css.mjs +0 -0
- package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.005-worker-dispatch.mjs +0 -0
- package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.006-fetch-handler.mjs +32 -0
- package/dist/esm-node/builder/generator/getBuilderEnvironments.mjs +1 -0
- package/dist/esm-node/index.mjs +2 -0
- package/dist/esm-node/plugins/backend-federation/codegen.mjs +158 -0
- package/dist/esm-node/plugins/backend-federation/config.mjs +142 -0
- package/dist/esm-node/plugins/backend-federation/emit.mjs +89 -0
- package/dist/esm-node/plugins/backendFederationBuild.mjs +2 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare/artifacts.mjs +65 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare/constants.mjs +34 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare/delivery-unit.mjs +68 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare/i18n-worker.mjs +98 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare/index.mjs +79 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare/security-policies.mjs +168 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare/types.mjs +1 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare/utils.mjs +13 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare/worker-manifest.mjs +119 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare/wrangler-config.mjs +136 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-contract.mjs +18 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-plan.mjs +46 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/identity.mjs +46 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/index.mjs +130 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/issues.mjs +11 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/manifest.mjs +46 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/mutation-policy.mjs +98 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/worker-bundles.mjs +69 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier.mjs +2 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare.mjs +1 -492
- package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.001-bootstrap-security.mjs +22 -0
- package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.002-assets-routes.mjs +0 -0
- package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.003-i18n-locales.mjs +0 -0
- package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.004-rendering-css.mjs +0 -0
- package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.005-worker-dispatch.mjs +0 -0
- package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.006-fetch-handler.mjs +32 -0
- package/dist/types/plugins/backend-federation/codegen.d.ts +82 -0
- package/dist/types/plugins/backend-federation/config.d.ts +103 -0
- package/dist/types/plugins/backend-federation/emit.d.ts +13 -0
- package/dist/types/plugins/backendFederationBuild.d.ts +2 -0
- package/dist/types/plugins/deploy/platforms/cloudflare/artifacts.d.ts +15 -0
- package/dist/types/plugins/deploy/platforms/cloudflare/constants.d.ts +23 -0
- package/dist/types/plugins/deploy/platforms/cloudflare/delivery-unit.d.ts +23 -0
- package/dist/types/plugins/deploy/platforms/cloudflare/i18n-worker.d.ts +21 -0
- package/dist/types/plugins/deploy/platforms/cloudflare/index.d.ts +2 -0
- package/dist/types/plugins/deploy/platforms/cloudflare/security-policies.d.ts +88 -0
- package/dist/types/plugins/deploy/platforms/cloudflare/types.d.ts +5 -0
- package/dist/types/plugins/deploy/platforms/cloudflare/utils.d.ts +6 -0
- package/dist/types/plugins/deploy/platforms/cloudflare/worker-manifest.d.ts +100 -0
- package/dist/types/plugins/deploy/platforms/cloudflare/wrangler-config.d.ts +39 -0
- package/dist/types/plugins/deploy/platforms/cloudflare-output-contract.d.ts +13 -0
- package/dist/types/plugins/deploy/platforms/cloudflare-output-plan.d.ts +33 -0
- package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/identity.d.ts +4 -0
- package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/index.d.ts +18 -0
- package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/issues.d.ts +14 -0
- package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/manifest.d.ts +2 -0
- package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/mutation-policy.d.ts +13 -0
- package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/worker-bundles.d.ts +16 -0
- package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier.d.ts +1 -0
- package/dist/types/plugins/deploy/platforms/cloudflare.d.ts +1 -2
- package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.001-bootstrap-security.d.mts +1 -0
- package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.002-assets-routes.d.mts +1 -0
- package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.003-i18n-locales.d.mts +1 -0
- package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.004-rendering-css.d.mts +1 -0
- package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.005-worker-dispatch.d.mts +1 -0
- package/dist/types/types/config/cloudflareDeploy.d.ts +22 -0
- package/dist/types/types/config/deploy.d.ts +15 -2
- package/lib/types.d.ts +2 -3
- package/package.json +17 -11
- package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.mjs +0 -576
- package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.mjs +0 -576
- package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.mjs +0 -576
- /package/dist/types/plugins/deploy/platforms/templates/{cloudflare-entry.d.mts → cloudflare-entry.006-fetch-handler.d.mts} +0 -0
|
@@ -1,493 +1,2 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
-
|
|
3
|
-
import { fs } from "@modern-js/utils";
|
|
4
|
-
import { readTemplate } from "../utils/index.mjs";
|
|
5
|
-
const WORKER_ENTRY = 'server/index.mjs';
|
|
6
|
-
const WORKER_MANIFEST = 'server/modern-worker-manifest.json';
|
|
7
|
-
const WRANGLER_CONFIG_FILE = 'wrangler.json';
|
|
8
|
-
const OUTPUT_PACKAGE_FILE = 'package.json';
|
|
9
|
-
const ASSETS_BINDING = 'ASSETS';
|
|
10
|
-
const ROUTE_SPEC_FILE = 'route.json';
|
|
11
|
-
const ROUTE_SPEC_OUTPUT = `server/${ROUTE_SPEC_FILE}`;
|
|
12
|
-
const LOADABLE_STATS_FILE = 'loadable-stats.json';
|
|
13
|
-
const ROUTE_MANIFEST_FILE = 'routes-manifest.json';
|
|
14
|
-
const PUBLIC_ASSETS_DIRECTORY = 'public';
|
|
15
|
-
const WORKER_BUNDLE_DIRECTORY = 'worker';
|
|
16
|
-
const SERVER_BUNDLE_DIRECTORY = 'bundles';
|
|
17
|
-
const SERVER_OUTPUT_DIRECTORY = 'server';
|
|
18
|
-
const DEFAULT_SERVER_ONLY_PUBLIC_ASSET_EXCLUDES = [
|
|
19
|
-
'api',
|
|
20
|
-
'shared'
|
|
21
|
-
];
|
|
22
|
-
const BFF_EFFECT_WORKER_ENTRY = `${WORKER_BUNDLE_DIRECTORY}/__modern_bff_effect.js`;
|
|
23
|
-
const EFFECT_BFF_CLOUDFLARE_IMPORT_GUIDANCE = 'Ensure the Effect API entry exists at api/index.ts or bff.effect.entry, and import Cloudflare edge handlers from @modern-js/plugin-bff/effect-edge instead of lambda/Hono server helpers.';
|
|
24
|
-
const DEFAULT_COMPATIBILITY_DATE = '2026-06-02';
|
|
25
|
-
const COMPATIBILITY_DATE_PATTERN = /^\d{4}-\d{2}-\d{2}$/u;
|
|
26
|
-
const REQUIRED_COMPATIBILITY_FLAGS = [
|
|
27
|
-
'nodejs_compat',
|
|
28
|
-
'global_fetch_strictly_public'
|
|
29
|
-
];
|
|
30
|
-
const RESERVED_ARTIFACT_DESTINATION_FILES = new Set([
|
|
31
|
-
WRANGLER_CONFIG_FILE,
|
|
32
|
-
OUTPUT_PACKAGE_FILE
|
|
33
|
-
]);
|
|
34
|
-
const RESERVED_ARTIFACT_DESTINATION_DIRECTORIES = new Set([
|
|
35
|
-
PUBLIC_ASSETS_DIRECTORY,
|
|
36
|
-
SERVER_OUTPUT_DIRECTORY,
|
|
37
|
-
WORKER_BUNDLE_DIRECTORY
|
|
38
|
-
]);
|
|
39
|
-
const DEFAULT_SECURITY_HEADERS = {
|
|
40
|
-
referrerPolicy: 'strict-origin-when-cross-origin',
|
|
41
|
-
contentTypeOptions: 'nosniff',
|
|
42
|
-
permissionsPolicy: 'camera=(), geolocation=(), microphone=(), payment=(), usb=()'
|
|
43
|
-
};
|
|
44
|
-
const DEFAULT_CORS_ALLOWED_METHODS = [
|
|
45
|
-
'GET',
|
|
46
|
-
'HEAD',
|
|
47
|
-
'POST',
|
|
48
|
-
'PUT',
|
|
49
|
-
'PATCH',
|
|
50
|
-
'DELETE',
|
|
51
|
-
'OPTIONS'
|
|
52
|
-
];
|
|
53
|
-
const DEFAULT_CSP_DIRECTIVES = {
|
|
54
|
-
'base-uri': [
|
|
55
|
-
"'self'"
|
|
56
|
-
],
|
|
57
|
-
'connect-src': [
|
|
58
|
-
"'self'",
|
|
59
|
-
'https:',
|
|
60
|
-
'http:',
|
|
61
|
-
'wss:',
|
|
62
|
-
'ws:'
|
|
63
|
-
],
|
|
64
|
-
'default-src': [
|
|
65
|
-
"'self'"
|
|
66
|
-
],
|
|
67
|
-
'font-src': [
|
|
68
|
-
"'self'",
|
|
69
|
-
'data:',
|
|
70
|
-
'https:',
|
|
71
|
-
'http:'
|
|
72
|
-
],
|
|
73
|
-
'form-action': [
|
|
74
|
-
"'self'"
|
|
75
|
-
],
|
|
76
|
-
'frame-ancestors': [
|
|
77
|
-
"'self'"
|
|
78
|
-
],
|
|
79
|
-
'img-src': [
|
|
80
|
-
"'self'",
|
|
81
|
-
'data:',
|
|
82
|
-
'blob:',
|
|
83
|
-
'https:',
|
|
84
|
-
'http:'
|
|
85
|
-
],
|
|
86
|
-
'manifest-src': [
|
|
87
|
-
"'self'",
|
|
88
|
-
'https:',
|
|
89
|
-
'http:'
|
|
90
|
-
],
|
|
91
|
-
'object-src': [
|
|
92
|
-
"'none'"
|
|
93
|
-
],
|
|
94
|
-
"script-src": [
|
|
95
|
-
"'self'",
|
|
96
|
-
"'unsafe-inline'",
|
|
97
|
-
"'unsafe-eval'",
|
|
98
|
-
'https:',
|
|
99
|
-
'http:',
|
|
100
|
-
'blob:'
|
|
101
|
-
],
|
|
102
|
-
'style-src': [
|
|
103
|
-
"'self'",
|
|
104
|
-
"'unsafe-inline'",
|
|
105
|
-
'https:',
|
|
106
|
-
'http:'
|
|
107
|
-
],
|
|
108
|
-
'worker-src': [
|
|
109
|
-
"'self'",
|
|
110
|
-
'blob:'
|
|
111
|
-
]
|
|
112
|
-
};
|
|
113
|
-
const getCompatibilityDate = (modernConfig)=>{
|
|
114
|
-
const configuredDate = modernConfig.deploy?.worker?.compatibilityDate?.trim();
|
|
115
|
-
const compatibilityDate = configuredDate || DEFAULT_COMPATIBILITY_DATE;
|
|
116
|
-
if (!COMPATIBILITY_DATE_PATTERN.test(compatibilityDate)) throw new Error(`deploy.worker.compatibilityDate must use YYYY-MM-DD, received ${JSON.stringify(compatibilityDate)}.`);
|
|
117
|
-
return compatibilityDate;
|
|
118
|
-
};
|
|
119
|
-
const getWorkerName = (appDirectory)=>{
|
|
120
|
-
const basename = node_path.basename(appDirectory);
|
|
121
|
-
return basename.replace(/[^a-zA-Z0-9-_]/g, '-') || 'modern-cloudflare-worker';
|
|
122
|
-
};
|
|
123
|
-
const getConfiguredWorkerName = (appDirectory, modernConfig)=>{
|
|
124
|
-
const configuredName = modernConfig.deploy?.worker?.name?.trim();
|
|
125
|
-
return configuredName || getWorkerName(appDirectory);
|
|
126
|
-
};
|
|
127
|
-
const normalizeRelativePath = (value, label, scope = 'app output')=>{
|
|
128
|
-
if ('string' != typeof value) throw new Error(`${label} must be a relative path inside the ${scope}.`);
|
|
129
|
-
const normalized = value.trim().replace(/\\/g, '/').replace(/^\.\/+/u, '').replace(/\/+$/u, '');
|
|
130
|
-
const segments = normalized.split('/');
|
|
131
|
-
if (!normalized || node_path.isAbsolute(normalized) || '.' === normalized || segments.includes('..')) throw new Error(`${label} must be a relative path inside the ${scope}.`);
|
|
132
|
-
return normalized;
|
|
133
|
-
};
|
|
134
|
-
const normalizeDirectiveValues = (value)=>{
|
|
135
|
-
const values = Array.isArray(value) ? value : [
|
|
136
|
-
value
|
|
137
|
-
];
|
|
138
|
-
return [
|
|
139
|
-
...new Set(values.map((entry)=>entry.trim()).filter(Boolean))
|
|
140
|
-
];
|
|
141
|
-
};
|
|
142
|
-
const appendDirectiveValues = (directives, name, values)=>{
|
|
143
|
-
if (!values?.length) return;
|
|
144
|
-
directives[name] = normalizeDirectiveValues([
|
|
145
|
-
...directives[name] ?? [],
|
|
146
|
-
...values
|
|
147
|
-
]);
|
|
148
|
-
};
|
|
149
|
-
const createContentSecurityPolicy = (config)=>{
|
|
150
|
-
const mode = config?.mode ?? 'report-only';
|
|
151
|
-
if ('off' === mode) return {
|
|
152
|
-
mode,
|
|
153
|
-
directives: {},
|
|
154
|
-
reason: config?.reason
|
|
155
|
-
};
|
|
156
|
-
const directives = Object.fromEntries(Object.entries(DEFAULT_CSP_DIRECTIVES).map(([name, values])=>[
|
|
157
|
-
name,
|
|
158
|
-
[
|
|
159
|
-
...values
|
|
160
|
-
]
|
|
161
|
-
]));
|
|
162
|
-
for (const [name, value] of Object.entries(config?.directives ?? {}))if (false === value) delete directives[name];
|
|
163
|
-
else directives[name] = normalizeDirectiveValues(value);
|
|
164
|
-
if (config?.frameAncestors === false) delete directives['frame-ancestors'];
|
|
165
|
-
else if (config?.frameAncestors) directives['frame-ancestors'] = normalizeDirectiveValues(config.frameAncestors);
|
|
166
|
-
appendDirectiveValues(directives, "script-src", config?.additionalScriptSrc);
|
|
167
|
-
appendDirectiveValues(directives, 'style-src', config?.additionalStyleSrc);
|
|
168
|
-
appendDirectiveValues(directives, 'connect-src', config?.additionalConnectSrc);
|
|
169
|
-
appendDirectiveValues(directives, 'img-src', config?.additionalImgSrc);
|
|
170
|
-
if (config?.reportUri) directives['report-uri'] = [
|
|
171
|
-
config.reportUri
|
|
172
|
-
];
|
|
173
|
-
return {
|
|
174
|
-
mode,
|
|
175
|
-
directives,
|
|
176
|
-
reason: config?.reason
|
|
177
|
-
};
|
|
178
|
-
};
|
|
179
|
-
const createNoindexPolicy = (noindex)=>{
|
|
180
|
-
if (false === noindex) return {
|
|
181
|
-
workersDev: false,
|
|
182
|
-
localhost: false,
|
|
183
|
-
previewHostnames: []
|
|
184
|
-
};
|
|
185
|
-
if (true === noindex || void 0 === noindex) return {
|
|
186
|
-
workersDev: true,
|
|
187
|
-
localhost: true,
|
|
188
|
-
previewHostnames: []
|
|
189
|
-
};
|
|
190
|
-
return {
|
|
191
|
-
workersDev: noindex.workersDev ?? true,
|
|
192
|
-
localhost: noindex.localhost ?? true,
|
|
193
|
-
previewHostnames: noindex.previewHostnames ?? [],
|
|
194
|
-
reason: noindex.reason
|
|
195
|
-
};
|
|
196
|
-
};
|
|
197
|
-
const createCloudflareWorkerCorsPolicy = (cors)=>({
|
|
198
|
-
assets: cors?.assets ?? true,
|
|
199
|
-
allowedOrigins: normalizeDirectiveValues(cors?.allowedOrigins ?? []),
|
|
200
|
-
allowedMethods: cors?.allowedMethods?.length ? normalizeDirectiveValues(cors.allowedMethods.map((method)=>method.toUpperCase())) : DEFAULT_CORS_ALLOWED_METHODS,
|
|
201
|
-
allowedHeaders: cors?.allowedHeaders?.length ? normalizeDirectiveValues(cors.allowedHeaders) : [
|
|
202
|
-
'*'
|
|
203
|
-
],
|
|
204
|
-
reason: cors?.reason
|
|
205
|
-
});
|
|
206
|
-
const createCloudflareWorkerSecurityPolicy = (modernConfig)=>{
|
|
207
|
-
const security = modernConfig.deploy?.worker?.security;
|
|
208
|
-
if (security?.enabled === false) return {
|
|
209
|
-
enabled: false,
|
|
210
|
-
cors: createCloudflareWorkerCorsPolicy(security.cors),
|
|
211
|
-
reason: security.reason
|
|
212
|
-
};
|
|
213
|
-
return {
|
|
214
|
-
enabled: true,
|
|
215
|
-
headers: {
|
|
216
|
-
referrerPolicy: security?.headers?.referrerPolicy ?? DEFAULT_SECURITY_HEADERS.referrerPolicy,
|
|
217
|
-
contentTypeOptions: security?.headers?.contentTypeOptions ?? DEFAULT_SECURITY_HEADERS.contentTypeOptions,
|
|
218
|
-
permissionsPolicy: security?.headers?.permissionsPolicy ?? DEFAULT_SECURITY_HEADERS.permissionsPolicy
|
|
219
|
-
},
|
|
220
|
-
contentSecurityPolicy: createContentSecurityPolicy(security?.contentSecurityPolicy),
|
|
221
|
-
noindex: createNoindexPolicy(security?.noindex),
|
|
222
|
-
cors: createCloudflareWorkerCorsPolicy(security?.cors),
|
|
223
|
-
reason: security?.reason
|
|
224
|
-
};
|
|
225
|
-
};
|
|
226
|
-
const isJsonRecord = (value)=>'object' == typeof value && null !== value && !Array.isArray(value);
|
|
227
|
-
const getConfiguredWrangler = (modernConfig)=>{
|
|
228
|
-
const wrangler = modernConfig.deploy?.worker?.wrangler;
|
|
229
|
-
if (void 0 === wrangler) return {};
|
|
230
|
-
if (!isJsonRecord(wrangler)) throw new Error('deploy.worker.wrangler must be a JSON object.');
|
|
231
|
-
return wrangler;
|
|
232
|
-
};
|
|
233
|
-
const createWranglerCompatibilityFlags = (configuredFlags)=>{
|
|
234
|
-
if (void 0 === configuredFlags) return [
|
|
235
|
-
...REQUIRED_COMPATIBILITY_FLAGS
|
|
236
|
-
];
|
|
237
|
-
if (!Array.isArray(configuredFlags) || configuredFlags.some((flag)=>'string' != typeof flag)) throw new Error('deploy.worker.wrangler.compatibility_flags must be an array of strings.');
|
|
238
|
-
return [
|
|
239
|
-
...new Set([
|
|
240
|
-
...configuredFlags,
|
|
241
|
-
...REQUIRED_COMPATIBILITY_FLAGS
|
|
242
|
-
])
|
|
243
|
-
];
|
|
244
|
-
};
|
|
245
|
-
const createWranglerAssetsConfig = (configuredAssets)=>{
|
|
246
|
-
if (void 0 !== configuredAssets && !isJsonRecord(configuredAssets)) throw new Error('deploy.worker.wrangler.assets must be an object.');
|
|
247
|
-
return {
|
|
248
|
-
...isJsonRecord(configuredAssets) ? configuredAssets : {},
|
|
249
|
-
directory: `./${PUBLIC_ASSETS_DIRECTORY}`,
|
|
250
|
-
binding: ASSETS_BINDING,
|
|
251
|
-
run_worker_first: true
|
|
252
|
-
};
|
|
253
|
-
};
|
|
254
|
-
const assertNonEmptyString = (value, label)=>{
|
|
255
|
-
if ('string' != typeof value || 0 === value.trim().length) throw new Error(`${label} must be a non-empty string.`);
|
|
256
|
-
return value.trim();
|
|
257
|
-
};
|
|
258
|
-
const normalizeD1Database = (database, index)=>{
|
|
259
|
-
const binding = assertNonEmptyString(database.binding, `deploy.worker.d1Databases[${index}].binding`);
|
|
260
|
-
const databaseName = assertNonEmptyString(database.databaseName, `deploy.worker.d1Databases[${index}].databaseName`);
|
|
261
|
-
const databaseId = assertNonEmptyString(database.databaseId, `deploy.worker.d1Databases[${index}].databaseId`);
|
|
262
|
-
const migrationsDir = void 0 === database.migrationsDir ? void 0 : normalizeRelativePath(database.migrationsDir, `deploy.worker.d1Databases[${index}].migrationsDir`, 'app root');
|
|
263
|
-
const previewDatabaseId = void 0 === database.previewDatabaseId ? void 0 : assertNonEmptyString(database.previewDatabaseId, `deploy.worker.d1Databases[${index}].previewDatabaseId`);
|
|
264
|
-
return {
|
|
265
|
-
binding,
|
|
266
|
-
database_name: databaseName,
|
|
267
|
-
database_id: databaseId,
|
|
268
|
-
...void 0 === migrationsDir ? {} : {
|
|
269
|
-
migrations_dir: migrationsDir
|
|
270
|
-
},
|
|
271
|
-
...void 0 === previewDatabaseId ? {} : {
|
|
272
|
-
preview_database_id: previewDatabaseId
|
|
273
|
-
},
|
|
274
|
-
...void 0 === database.remote ? {} : {
|
|
275
|
-
remote: database.remote
|
|
276
|
-
}
|
|
277
|
-
};
|
|
278
|
-
};
|
|
279
|
-
const createWranglerD1Databases = (modernConfig, configuredWranglerD1)=>{
|
|
280
|
-
const d1Databases = modernConfig.deploy?.worker?.d1Databases;
|
|
281
|
-
if (void 0 === d1Databases) return configuredWranglerD1;
|
|
282
|
-
if (void 0 !== configuredWranglerD1) throw new Error('Use deploy.worker.d1Databases or deploy.worker.wrangler.d1_databases, not both.');
|
|
283
|
-
if (!Array.isArray(d1Databases)) throw new Error('deploy.worker.d1Databases must be an array.');
|
|
284
|
-
return d1Databases.map(normalizeD1Database);
|
|
285
|
-
};
|
|
286
|
-
const createWranglerConfig = (appDirectory, modernConfig)=>{
|
|
287
|
-
const wrangler = getConfiguredWrangler(modernConfig);
|
|
288
|
-
const d1Databases = createWranglerD1Databases(modernConfig, wrangler.d1_databases);
|
|
289
|
-
return {
|
|
290
|
-
$schema: 'node_modules/wrangler/config-schema.json',
|
|
291
|
-
name: getConfiguredWorkerName(appDirectory, modernConfig),
|
|
292
|
-
compatibility_date: getCompatibilityDate(modernConfig),
|
|
293
|
-
...wrangler,
|
|
294
|
-
main: WORKER_ENTRY,
|
|
295
|
-
compatibility_flags: createWranglerCompatibilityFlags(wrangler.compatibility_flags),
|
|
296
|
-
assets: createWranglerAssetsConfig(wrangler.assets),
|
|
297
|
-
...void 0 === d1Databases ? {} : {
|
|
298
|
-
d1_databases: d1Databases
|
|
299
|
-
}
|
|
300
|
-
};
|
|
301
|
-
};
|
|
302
|
-
const normalizeCloudflareArtifact = (artifact, index)=>{
|
|
303
|
-
const from = normalizeRelativePath(artifact.from, `deploy.worker.artifacts[${index}].from`, 'app root');
|
|
304
|
-
const to = normalizeRelativePath(artifact.to, `deploy.worker.artifacts[${index}].to`, 'Cloudflare output');
|
|
305
|
-
const [topLevelDestination] = to.split('/');
|
|
306
|
-
const reservedDestination = RESERVED_ARTIFACT_DESTINATION_FILES.has(to) ? to : topLevelDestination;
|
|
307
|
-
if (RESERVED_ARTIFACT_DESTINATION_FILES.has(to) || RESERVED_ARTIFACT_DESTINATION_DIRECTORIES.has(topLevelDestination)) throw new Error(`deploy.worker.artifacts[${index}].to must not target generated Cloudflare output path ${JSON.stringify(reservedDestination)}.`);
|
|
308
|
-
return {
|
|
309
|
-
from,
|
|
310
|
-
to,
|
|
311
|
-
index
|
|
312
|
-
};
|
|
313
|
-
};
|
|
314
|
-
const getCloudflareArtifacts = (modernConfig)=>(modernConfig.deploy?.worker?.artifacts ?? []).map(normalizeCloudflareArtifact);
|
|
315
|
-
const copyCloudflareArtifacts = async (appDirectory, outputDirectory, artifacts)=>{
|
|
316
|
-
for (const artifact of artifacts){
|
|
317
|
-
const sourcePath = node_path.join(appDirectory, artifact.from);
|
|
318
|
-
if (!await fs.pathExists(sourcePath)) throw new Error(`deploy.worker.artifacts[${artifact.index}].from does not exist: ${artifact.from}`);
|
|
319
|
-
await fs.copy(sourcePath, node_path.join(outputDirectory, artifact.to));
|
|
320
|
-
}
|
|
321
|
-
};
|
|
322
|
-
const copyCloudflareD1Migrations = async (appDirectory, outputDirectory, modernConfig)=>{
|
|
323
|
-
for (const [index, database] of (modernConfig.deploy?.worker?.d1Databases ?? []).entries()){
|
|
324
|
-
if (!database.migrationsDir) continue;
|
|
325
|
-
const migrationsDir = normalizeRelativePath(database.migrationsDir, `deploy.worker.d1Databases[${index}].migrationsDir`, 'app root');
|
|
326
|
-
const sourcePath = node_path.join(appDirectory, migrationsDir);
|
|
327
|
-
if (!await fs.pathExists(sourcePath)) throw new Error(`deploy.worker.d1Databases[${index}].migrationsDir does not exist: ${migrationsDir}`);
|
|
328
|
-
await fs.copy(sourcePath, node_path.join(outputDirectory, migrationsDir));
|
|
329
|
-
}
|
|
330
|
-
};
|
|
331
|
-
const readRouteSpec = async (outputDirectory)=>{
|
|
332
|
-
const routeSpecPath = node_path.join(outputDirectory, ROUTE_SPEC_OUTPUT);
|
|
333
|
-
if (!await fs.pathExists(routeSpecPath)) return {
|
|
334
|
-
routes: []
|
|
335
|
-
};
|
|
336
|
-
const routeSpec = await fs.readJSON(routeSpecPath);
|
|
337
|
-
return {
|
|
338
|
-
...routeSpec,
|
|
339
|
-
routes: Array.isArray(routeSpec.routes) ? routeSpec.routes : []
|
|
340
|
-
};
|
|
341
|
-
};
|
|
342
|
-
const createMissingEffectBffWorkerError = (outputDirectory, worker)=>new Error(`Cloudflare Effect API runtime is configured, but the BFF worker bundle is missing: ${node_path.join(outputDirectory, worker)}. ${EFFECT_BFF_CLOUDFLARE_IMPORT_GUIDANCE}`);
|
|
343
|
-
const createWorkerManifest = async (outputDirectory, modernConfig)=>{
|
|
344
|
-
const routeSpec = await readRouteSpec(outputDirectory);
|
|
345
|
-
const routes = await Promise.all(routeSpec.routes.map(async (route)=>{
|
|
346
|
-
const worker = 'string' == typeof route.worker ? route.worker : void 0;
|
|
347
|
-
return {
|
|
348
|
-
urlPath: route.urlPath,
|
|
349
|
-
entryName: route.entryName,
|
|
350
|
-
entryPath: route.entryPath,
|
|
351
|
-
isSSR: Boolean(route.isSSR),
|
|
352
|
-
worker,
|
|
353
|
-
workerExists: worker ? await fs.pathExists(node_path.join(outputDirectory, worker)) : false
|
|
354
|
-
};
|
|
355
|
-
}));
|
|
356
|
-
const bffPrefix = modernConfig.bff?.prefix;
|
|
357
|
-
const primaryBffPrefix = Array.isArray(bffPrefix) ? bffPrefix[0] : bffPrefix;
|
|
358
|
-
const isEffectApi = Boolean(modernConfig.bff) && modernConfig.bff?.runtimeFramework !== 'hono';
|
|
359
|
-
const effectApiWorkerExists = await fs.pathExists(node_path.join(outputDirectory, BFF_EFFECT_WORKER_ENTRY));
|
|
360
|
-
if (isEffectApi && primaryBffPrefix && !effectApiWorkerExists) throw createMissingEffectBffWorkerError(outputDirectory, BFF_EFFECT_WORKER_ENTRY);
|
|
361
|
-
return {
|
|
362
|
-
version: 1,
|
|
363
|
-
runtime: {
|
|
364
|
-
type: 'cloudflare-module-worker',
|
|
365
|
-
entry: WORKER_ENTRY,
|
|
366
|
-
fetchExport: true,
|
|
367
|
-
nodeListen: false
|
|
368
|
-
},
|
|
369
|
-
assets: {
|
|
370
|
-
binding: ASSETS_BINDING,
|
|
371
|
-
directory: `./${PUBLIC_ASSETS_DIRECTORY}`,
|
|
372
|
-
runWorkerFirst: true
|
|
373
|
-
},
|
|
374
|
-
routeSpec: {
|
|
375
|
-
file: ROUTE_SPEC_OUTPUT,
|
|
376
|
-
routes
|
|
377
|
-
},
|
|
378
|
-
workerBundles: {
|
|
379
|
-
directory: WORKER_BUNDLE_DIRECTORY,
|
|
380
|
-
format: 'commonjs',
|
|
381
|
-
importableFromModuleWorker: true,
|
|
382
|
-
requestHandlerExport: 'requestHandler'
|
|
383
|
-
},
|
|
384
|
-
resources: {
|
|
385
|
-
loadableStats: LOADABLE_STATS_FILE,
|
|
386
|
-
routeManifest: ROUTE_MANIFEST_FILE
|
|
387
|
-
},
|
|
388
|
-
security: createCloudflareWorkerSecurityPolicy(modernConfig),
|
|
389
|
-
bff: isEffectApi && primaryBffPrefix && effectApiWorkerExists ? {
|
|
390
|
-
runtimeFramework: 'effect',
|
|
391
|
-
prefix: primaryBffPrefix,
|
|
392
|
-
worker: BFF_EFFECT_WORKER_ENTRY
|
|
393
|
-
} : void 0
|
|
394
|
-
};
|
|
395
|
-
};
|
|
396
|
-
const createWorkerModuleLoaders = (manifest)=>{
|
|
397
|
-
const imports = new Map();
|
|
398
|
-
for (const route of manifest.routeSpec.routes)if (route.worker && route.workerExists) {
|
|
399
|
-
const importPath = `../${String(route.worker).replace(/^\/+/u, '')}`;
|
|
400
|
-
imports.set(route.worker, `() => import(${JSON.stringify(importPath)})`);
|
|
401
|
-
}
|
|
402
|
-
if (manifest.bff?.worker) {
|
|
403
|
-
const importPath = `../${String(manifest.bff.worker).replace(/^\/+/u, '')}`;
|
|
404
|
-
imports.set(manifest.bff.worker, `() => import(${JSON.stringify(importPath)})`);
|
|
405
|
-
}
|
|
406
|
-
if (0 === imports.size) return '{}';
|
|
407
|
-
const loaders = [
|
|
408
|
-
...imports.entries()
|
|
409
|
-
].map(([worker, loader])=>`${JSON.stringify(worker)}: ${loader}`);
|
|
410
|
-
return `{\n${loaders.join(',\n')}\n}`;
|
|
411
|
-
};
|
|
412
|
-
const getPublicAssetExcludes = (appDirectory, modernConfig)=>[
|
|
413
|
-
...DEFAULT_SERVER_ONLY_PUBLIC_ASSET_EXCLUDES.filter((directory)=>{
|
|
414
|
-
try {
|
|
415
|
-
return fs.statSync(node_path.join(appDirectory, directory)).isDirectory();
|
|
416
|
-
} catch {
|
|
417
|
-
return false;
|
|
418
|
-
}
|
|
419
|
-
}),
|
|
420
|
-
...modernConfig.deploy?.worker?.publicAssetExcludes ?? []
|
|
421
|
-
].map((entry)=>normalizeRelativePath(entry, 'deploy.worker.publicAssetExcludes'));
|
|
422
|
-
const shouldCopyToPublicAssets = (src, distDirectory, publicAssetExcludes)=>{
|
|
423
|
-
const relativePath = node_path.relative(distDirectory, src);
|
|
424
|
-
if (!relativePath) return true;
|
|
425
|
-
const normalizedRelativePath = relativePath.replace(/\\/g, '/');
|
|
426
|
-
const [topLevelDirectory] = normalizedRelativePath.split('/');
|
|
427
|
-
return normalizedRelativePath !== ROUTE_SPEC_FILE && topLevelDirectory !== WORKER_BUNDLE_DIRECTORY && topLevelDirectory !== SERVER_BUNDLE_DIRECTORY && !publicAssetExcludes.some((exclude)=>normalizedRelativePath === exclude || normalizedRelativePath.startsWith(`${exclude}/`));
|
|
428
|
-
};
|
|
429
|
-
const shouldCopyToWorkerBundle = (src, workerBundleDirectory)=>{
|
|
430
|
-
const relativePath = node_path.relative(workerBundleDirectory, src);
|
|
431
|
-
if (!relativePath) return true;
|
|
432
|
-
const normalizedRelativePath = relativePath.replace(/\\/g, '/');
|
|
433
|
-
const basename = node_path.basename(normalizedRelativePath);
|
|
434
|
-
if (basename.startsWith('.') || normalizedRelativePath.includes('/.')) return false;
|
|
435
|
-
if (fs.statSync(src).isDirectory()) return true;
|
|
436
|
-
return [
|
|
437
|
-
'.cjs',
|
|
438
|
-
'.js',
|
|
439
|
-
'.mjs'
|
|
440
|
-
].includes(node_path.extname(normalizedRelativePath));
|
|
441
|
-
};
|
|
442
|
-
const createCloudflarePreset = ({ appContext, modernConfig })=>{
|
|
443
|
-
const { appDirectory, distDirectory } = appContext;
|
|
444
|
-
const outputDirectory = node_path.join(appDirectory, '.output');
|
|
445
|
-
const publicDirectory = node_path.join(outputDirectory, PUBLIC_ASSETS_DIRECTORY);
|
|
446
|
-
const workerEntryPath = node_path.join(outputDirectory, WORKER_ENTRY);
|
|
447
|
-
const workerManifestPath = node_path.join(outputDirectory, WORKER_MANIFEST);
|
|
448
|
-
const routeSpecOutputPath = node_path.join(outputDirectory, ROUTE_SPEC_OUTPUT);
|
|
449
|
-
const wranglerConfigPath = node_path.join(outputDirectory, WRANGLER_CONFIG_FILE);
|
|
450
|
-
const cloudflareArtifacts = getCloudflareArtifacts(modernConfig);
|
|
451
|
-
const publicAssetExcludes = getPublicAssetExcludes(appDirectory, modernConfig);
|
|
452
|
-
return {
|
|
453
|
-
async prepare () {
|
|
454
|
-
await fs.remove(outputDirectory);
|
|
455
|
-
},
|
|
456
|
-
async writeOutput () {
|
|
457
|
-
await fs.copy(distDirectory, publicDirectory, {
|
|
458
|
-
filter: (src)=>shouldCopyToPublicAssets(src, distDirectory, publicAssetExcludes)
|
|
459
|
-
});
|
|
460
|
-
await fs.ensureDir(node_path.dirname(workerEntryPath));
|
|
461
|
-
await fs.ensureDir(node_path.dirname(workerManifestPath));
|
|
462
|
-
const routeSpecSourcePath = node_path.join(distDirectory, ROUTE_SPEC_FILE);
|
|
463
|
-
if (await fs.pathExists(routeSpecSourcePath)) await fs.copy(routeSpecSourcePath, routeSpecOutputPath);
|
|
464
|
-
const workerBundleSourceDirectory = node_path.join(distDirectory, WORKER_BUNDLE_DIRECTORY);
|
|
465
|
-
const workerBundleOutputDirectory = node_path.join(outputDirectory, WORKER_BUNDLE_DIRECTORY);
|
|
466
|
-
if (await fs.pathExists(workerBundleSourceDirectory)) {
|
|
467
|
-
await fs.copy(workerBundleSourceDirectory, workerBundleOutputDirectory, {
|
|
468
|
-
filter: (src)=>shouldCopyToWorkerBundle(src, workerBundleSourceDirectory)
|
|
469
|
-
});
|
|
470
|
-
await fs.writeJSON(node_path.join(workerBundleOutputDirectory, 'package.json'), {
|
|
471
|
-
type: 'commonjs'
|
|
472
|
-
});
|
|
473
|
-
}
|
|
474
|
-
await copyCloudflareArtifacts(appDirectory, outputDirectory, cloudflareArtifacts);
|
|
475
|
-
await copyCloudflareD1Migrations(appDirectory, outputDirectory, modernConfig);
|
|
476
|
-
await fs.writeJSON(wranglerConfigPath, createWranglerConfig(appDirectory, modernConfig), {
|
|
477
|
-
spaces: 2
|
|
478
|
-
});
|
|
479
|
-
await fs.writeJSON(workerManifestPath, await createWorkerManifest(outputDirectory, modernConfig), {
|
|
480
|
-
spaces: 2
|
|
481
|
-
});
|
|
482
|
-
await fs.writeJSON(node_path.join(outputDirectory, OUTPUT_PACKAGE_FILE), {
|
|
483
|
-
type: 'module'
|
|
484
|
-
});
|
|
485
|
-
},
|
|
486
|
-
async genEntry () {
|
|
487
|
-
const template = await readTemplate('cloudflare-entry.mjs');
|
|
488
|
-
const manifest = await fs.readJSON(workerManifestPath);
|
|
489
|
-
await fs.writeFile(workerEntryPath, template.replace('p_workerManifest', JSON.stringify(manifest, null, 2)).replace('p_workerModuleLoaders', createWorkerModuleLoaders(manifest)));
|
|
490
|
-
}
|
|
491
|
-
};
|
|
492
|
-
};
|
|
493
|
-
export { createCloudflarePreset };
|
|
2
|
+
export { createCloudflarePreset } from "./cloudflare/index.mjs";
|
package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.001-bootstrap-security.mjs
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const MODERN_WORKER_MANIFEST = p_workerManifest;
|
|
2
|
+
p_workerModuleLoaders;
|
|
3
|
+
new Map();
|
|
4
|
+
new Map();
|
|
5
|
+
new Map();
|
|
6
|
+
const CORS_POLICY = MODERN_WORKER_MANIFEST.security?.cors || {};
|
|
7
|
+
CORS_POLICY.assets;
|
|
8
|
+
(CORS_POLICY.allowedOrigins || []).map((origin)=>String(origin).toLowerCase());
|
|
9
|
+
(CORS_POLICY.allowedMethods?.length ? CORS_POLICY.allowedMethods : [
|
|
10
|
+
'GET',
|
|
11
|
+
'HEAD',
|
|
12
|
+
'POST',
|
|
13
|
+
'PUT',
|
|
14
|
+
'PATCH',
|
|
15
|
+
'DELETE',
|
|
16
|
+
'OPTIONS'
|
|
17
|
+
]).join(', ');
|
|
18
|
+
(CORS_POLICY.allowedHeaders?.length ? CORS_POLICY.allowedHeaders : [
|
|
19
|
+
'*'
|
|
20
|
+
]).join(', ');
|
|
21
|
+
globalThis.__dirname ??= '/';
|
|
22
|
+
globalThis.__filename ??= '/index.js';
|
package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.002-assets-routes.mjs
ADDED
|
File without changes
|
package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.003-i18n-locales.mjs
ADDED
|
File without changes
|
package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.004-rendering-css.mjs
ADDED
|
File without changes
|
package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.005-worker-dispatch.mjs
ADDED
|
File without changes
|
package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.006-fetch-handler.mjs
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
async fetch (request, env, ctx) {
|
|
3
|
+
const corsPreflightResponse = await createCorsPreflightResponse(request, env);
|
|
4
|
+
if (corsPreflightResponse) return finalizeResponseForRequest(corsPreflightResponse, request);
|
|
5
|
+
const bffResponse = await dispatchBffRequest(request, env);
|
|
6
|
+
if (bffResponse) return finalizeResponseForRequest(withAppCorsHeaders(bffResponse, request), request);
|
|
7
|
+
const serviceBindingResponse = await dispatchServiceBindingRequest(request, env);
|
|
8
|
+
if (serviceBindingResponse) return finalizeResponseForRequest(withAppCorsHeaders(serviceBindingResponse, request), request);
|
|
9
|
+
const route = findRoute(request);
|
|
10
|
+
const { pathname } = new URL(request.url);
|
|
11
|
+
if (isAssetLikePathname(pathname) && !routeMatchesExactly(route, pathname)) {
|
|
12
|
+
const assetResponse = await fetchAsset(request, env);
|
|
13
|
+
if (assetResponse) return finalizeResponseForRequest(assetResponse, request);
|
|
14
|
+
return finalizeResponseForRequest(withAppCorsHeaders(new Response('Not found', {
|
|
15
|
+
status: 404
|
|
16
|
+
}), request), request);
|
|
17
|
+
}
|
|
18
|
+
const localeRedirectResponse = createLocaleRedirectResponseForRequest(route, request);
|
|
19
|
+
if (localeRedirectResponse) return finalizeResponseForRequest(withAppCorsHeaders(localeRedirectResponse, request), request);
|
|
20
|
+
if (route?.worker) {
|
|
21
|
+
const renderableRequest = createRenderableRequest(request);
|
|
22
|
+
return finalizeResponseForRequest(withAppCorsHeaders(await dispatchRouteWorker(route, renderableRequest, env, ctx), request), request);
|
|
23
|
+
}
|
|
24
|
+
const htmlResponse = await fetchRouteHtml(route, request, env);
|
|
25
|
+
if (htmlResponse) return finalizeResponseForRequest(htmlResponse, request);
|
|
26
|
+
const assetResponse = await fetchAsset(request, env);
|
|
27
|
+
if (assetResponse) return finalizeResponseForRequest(assetResponse, request);
|
|
28
|
+
return finalizeResponseForRequest(withAppCorsHeaders(new Response('Not found', {
|
|
29
|
+
status: 404
|
|
30
|
+
}), request), request);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { type BackendFederationApp } from './config';
|
|
2
|
+
export declare const createBackendRemoteEntrySource: (workspaceRoot: string, app: BackendFederationApp, effectApiPath: string, entryPath: string) => string;
|
|
3
|
+
export declare const createBackendManifest: (workspaceRoot: string, distDirectory: string, app: BackendFederationApp) => {
|
|
4
|
+
schemaVersion: number;
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
version: string | undefined;
|
|
8
|
+
buildVersion: string | undefined;
|
|
9
|
+
metaData: {
|
|
10
|
+
name: string;
|
|
11
|
+
type: string;
|
|
12
|
+
buildInfo: {
|
|
13
|
+
buildVersion: string | undefined;
|
|
14
|
+
buildName: string | undefined;
|
|
15
|
+
};
|
|
16
|
+
remoteEntry: {
|
|
17
|
+
name: string;
|
|
18
|
+
path: string;
|
|
19
|
+
type: string;
|
|
20
|
+
};
|
|
21
|
+
globalName: string;
|
|
22
|
+
publicPath: string;
|
|
23
|
+
ssrRemoteEntry: {
|
|
24
|
+
name: string;
|
|
25
|
+
path: string;
|
|
26
|
+
type: string;
|
|
27
|
+
};
|
|
28
|
+
ssrPublicPath: string;
|
|
29
|
+
};
|
|
30
|
+
entry: {
|
|
31
|
+
file: string;
|
|
32
|
+
path: string;
|
|
33
|
+
type: string;
|
|
34
|
+
url: string;
|
|
35
|
+
};
|
|
36
|
+
exposes: {
|
|
37
|
+
id: string;
|
|
38
|
+
name: string;
|
|
39
|
+
path: string;
|
|
40
|
+
assets: {
|
|
41
|
+
js: {
|
|
42
|
+
async: never[];
|
|
43
|
+
sync: string[];
|
|
44
|
+
};
|
|
45
|
+
css: {
|
|
46
|
+
async: never[];
|
|
47
|
+
sync: never[];
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
}[];
|
|
51
|
+
shared: never[];
|
|
52
|
+
backendFederation: {
|
|
53
|
+
role: string;
|
|
54
|
+
name: string;
|
|
55
|
+
runtimeFramework: string;
|
|
56
|
+
strictEffectApproach: boolean;
|
|
57
|
+
contractVersion: string;
|
|
58
|
+
nodeAdapterVersion: string;
|
|
59
|
+
remoteType: string;
|
|
60
|
+
expose: string;
|
|
61
|
+
manifestUrl: string;
|
|
62
|
+
containerEntry: string;
|
|
63
|
+
source: {
|
|
64
|
+
module: string;
|
|
65
|
+
};
|
|
66
|
+
readinessPath: string;
|
|
67
|
+
openapiPath: string;
|
|
68
|
+
deliveryUnit?: import("@modern-js/utils/universal").DeliveryUnitContractBlock | undefined;
|
|
69
|
+
versionBoundary: {
|
|
70
|
+
invariant: string;
|
|
71
|
+
packageName: string | undefined;
|
|
72
|
+
version: string | undefined;
|
|
73
|
+
buildVersion: string | undefined;
|
|
74
|
+
uiManifestUrl?: string | undefined;
|
|
75
|
+
deliveryUnit?: {
|
|
76
|
+
unitId: string;
|
|
77
|
+
buildMarker: string;
|
|
78
|
+
sourceRevision: string;
|
|
79
|
+
} | undefined;
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
};
|