@bleedingdev/modern-js-server-core 3.9.0-ultramodern.4 → 3.9.0-ultramodern.6
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/adapters/node/index.js +4 -0
- package/dist/cjs/adapters/node/plugins/static.js +107 -29
- package/dist/cjs/index.js +10 -34
- package/dist/cjs/plugins/compat/index.js +1 -0
- package/dist/cjs/serverBase.js +58 -17
- package/dist/cjs/utils/error.js +0 -10
- package/dist/esm/adapters/node/index.mjs +1 -0
- package/dist/esm/adapters/node/plugins/static.mjs +107 -32
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/plugins/compat/index.mjs +1 -0
- package/dist/esm/serverBase.mjs +58 -17
- package/dist/esm/utils/error.mjs +0 -1
- package/dist/esm-node/adapters/node/index.mjs +1 -0
- package/dist/esm-node/adapters/node/plugins/static.mjs +107 -32
- package/dist/esm-node/index.mjs +1 -1
- package/dist/esm-node/plugins/compat/index.mjs +1 -0
- package/dist/esm-node/serverBase.mjs +58 -17
- package/dist/esm-node/utils/error.mjs +0 -1
- package/dist/types/adapters/node/index.d.ts +2 -0
- package/dist/types/adapters/node/plugins/static.d.ts +42 -4
- package/dist/types/index.d.ts +1 -2
- package/dist/types/serverBase.d.ts +6 -0
- package/dist/types/types/config/bff.d.ts +4 -15
- package/dist/types/types/config/server.d.ts +1 -3
- package/dist/types/types/plugins/plugin.d.ts +15 -1
- package/dist/types/utils/error.d.ts +0 -2
- package/package.json +5 -6
- package/dist/cjs/adapters/node/plugins/staticModuleFederation.js +0 -173
- package/dist/cjs/adapters/node/plugins/staticPrecompressed.js +0 -152
- package/dist/cjs/adapters/node/plugins/staticServing.js +0 -206
- package/dist/cjs/types/config/bffRuntime.js +0 -18
- package/dist/cjs/types/config/serverTelemetry.js +0 -18
- package/dist/esm/adapters/node/plugins/staticModuleFederation.mjs +0 -104
- package/dist/esm/adapters/node/plugins/staticPrecompressed.mjs +0 -111
- package/dist/esm/adapters/node/plugins/staticServing.mjs +0 -152
- package/dist/esm/types/config/bffRuntime.mjs +0 -0
- package/dist/esm/types/config/serverTelemetry.mjs +0 -0
- package/dist/esm-node/adapters/node/plugins/staticModuleFederation.mjs +0 -105
- package/dist/esm-node/adapters/node/plugins/staticPrecompressed.mjs +0 -112
- package/dist/esm-node/adapters/node/plugins/staticServing.mjs +0 -153
- package/dist/esm-node/types/config/bffRuntime.mjs +0 -1
- package/dist/esm-node/types/config/serverTelemetry.mjs +0 -1
- package/dist/types/adapters/node/plugins/staticModuleFederation.d.ts +0 -13
- package/dist/types/adapters/node/plugins/staticPrecompressed.d.ts +0 -13
- package/dist/types/adapters/node/plugins/staticServing.d.ts +0 -25
- package/dist/types/types/config/bffRuntime.d.ts +0 -116
- package/dist/types/types/config/serverTelemetry.d.ts +0 -319
|
@@ -1,12 +1,50 @@
|
|
|
1
1
|
import type { ServerRoute } from '@modern-js/types';
|
|
2
2
|
import type { HtmlNormalizedConfig, Middleware, OutputNormalizedConfig, ServerNormalizedConfig, ServerPlugin } from '../../../types/index.js';
|
|
3
|
-
|
|
3
|
+
/** A selected file and the native response conventions to use for it. */
|
|
4
|
+
export type StaticAsset = {
|
|
5
|
+
filename: string;
|
|
6
|
+
kind: 'static' | 'public';
|
|
7
|
+
/** An alternate representation retains the original resource's MIME type. */
|
|
8
|
+
mimeFilename?: string;
|
|
9
|
+
responseHeaders?: ServerRoute['responseHeaders'];
|
|
10
|
+
/** True uses the served byte length; omitted preserves native length defaults. */
|
|
11
|
+
contentLength?: boolean;
|
|
12
|
+
/** Optional lexical containment boundary. Use real paths to contain symlinks. */
|
|
13
|
+
root?: string;
|
|
14
|
+
/** Resolve symlinks before checking root. Implies a regular file is required. */
|
|
15
|
+
realpath?: boolean;
|
|
16
|
+
};
|
|
17
|
+
export type StaticAssetRequest = {
|
|
18
|
+
root: string;
|
|
19
|
+
pathPrefix: string;
|
|
20
|
+
};
|
|
21
|
+
/** Native serving of the selected file, optionally choosing another representation. */
|
|
22
|
+
export type ServeStaticAsset = (representation?: Partial<Pick<StaticAsset, 'filename' | 'contentLength'>>) => Promise<Response | null>;
|
|
23
|
+
/**
|
|
24
|
+
* Trusted server extension. Undefined uses the native file; null skips it.
|
|
25
|
+
* A returned response is final. Exceptions use the normal server error handler.
|
|
26
|
+
*/
|
|
27
|
+
export type StaticAssetResponder = (context: Parameters<Middleware>[0], asset: StaticAsset, serve: ServeStaticAsset, request: StaticAssetRequest) => Response | null | undefined | Promise<Response | null | undefined>;
|
|
28
|
+
/**
|
|
29
|
+
* Handles requests outside the native static pattern. The continuation only
|
|
30
|
+
* tries native public routes; it returns null on a miss and never calls the next
|
|
31
|
+
* middleware. Returning null from this hook continues the middleware chain.
|
|
32
|
+
*/
|
|
33
|
+
export type StaticPublicFallbackResponder = (context: Parameters<Middleware>[0], respondPublic: () => Promise<Response | null>, request: StaticAssetRequest) => Response | null | Promise<Response | null>;
|
|
34
|
+
/** Read a selected file using native readers, MIME, headers and body conversion. */
|
|
35
|
+
export declare function serveStaticAsset(context: Parameters<Middleware>[0], asset: StaticAsset, respond?: (asset: StaticAsset, serve: ServeStaticAsset) => Promise<Response | null>): Promise<Response | null>;
|
|
36
|
+
export type ServerStaticPluginOptions = {
|
|
37
|
+
respondAsset?: StaticAssetResponder;
|
|
38
|
+
respondPublicFallback?: StaticPublicFallbackResponder;
|
|
39
|
+
};
|
|
40
|
+
export declare const serverStaticPlugin: (options?: ServerStaticPluginOptions) => ServerPlugin;
|
|
4
41
|
export type PublicMiddlwareOptions = {
|
|
5
42
|
pwd: string;
|
|
6
43
|
routes: ServerRoute[];
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export
|
|
44
|
+
pathPrefix?: string;
|
|
45
|
+
} & ServerStaticPluginOptions;
|
|
46
|
+
export declare function createPublicMiddleware({ pwd, routes, pathPrefix, respondAsset, respondPublicFallback, }: PublicMiddlwareOptions): Middleware;
|
|
47
|
+
export interface ServerStaticOptions extends ServerStaticPluginOptions {
|
|
10
48
|
pwd: string;
|
|
11
49
|
output: OutputNormalizedConfig;
|
|
12
50
|
html: HtmlNormalizedConfig;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -10,6 +10,5 @@ export * from './types/config/index.js';
|
|
|
10
10
|
export * from './types/plugins/index.js';
|
|
11
11
|
export * from './types/render.js';
|
|
12
12
|
export * from './types/requestHandler.js';
|
|
13
|
-
export
|
|
14
|
-
export { createErrorHtml, createSafeFailureHttpResult, createSafeJsonFailureResponse, ErrorDigest, getSafeFailureStatus, onError, } from './utils/index.js';
|
|
13
|
+
export { createErrorHtml, ErrorDigest, onError, } from './utils/index.js';
|
|
15
14
|
export { getPublicDirConfig, getPublicDirPatterns, getPublicDirRoutePrefixes, normalizePublicDir, normalizePublicDirPath, resolvePublicDirPaths, } from './utils/publicDir.js';
|
|
@@ -12,6 +12,8 @@ export declare class ServerBase<E extends Env = any> {
|
|
|
12
12
|
serverOptions: ServerBaseOptions;
|
|
13
13
|
private app;
|
|
14
14
|
private plugins;
|
|
15
|
+
private disposers;
|
|
16
|
+
private disposePromise?;
|
|
15
17
|
private serverContext;
|
|
16
18
|
constructor(options: ServerBaseOptions);
|
|
17
19
|
/**
|
|
@@ -20,6 +22,10 @@ export declare class ServerBase<E extends Env = any> {
|
|
|
20
22
|
* - apply middlewares
|
|
21
23
|
*/
|
|
22
24
|
init(): Promise<this>;
|
|
25
|
+
/** Register instance resources before initialization can fail. */
|
|
26
|
+
onDispose(disposer: () => void | Promise<void>): () => void;
|
|
27
|
+
/** Retire this instance and release every resource in reverse order once. */
|
|
28
|
+
dispose(): Promise<void>;
|
|
23
29
|
addPlugins(plugins: ServerPlugin[]): void;
|
|
24
30
|
get hooks(): ServerPluginHooks;
|
|
25
31
|
get all(): import("hono/types").HandlerInterface<E, "all", import("hono/types").BlankSchema, "/", "/">;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
+
import type { BffRuntimeFramework } from '@modern-js/plugin/server';
|
|
1
2
|
import type { HttpMethodDecider } from '@modern-js/types';
|
|
2
|
-
import type { BffCrossProjectPolicyUserConfig, BffEffectUserConfig, BffRuntimeFramework } from './bffRuntime.js';
|
|
3
|
-
export type { BffCrossProjectPolicyUserConfig, BffEffectDataPlatformBatchUserConfig, BffEffectDataPlatformSelectionUserConfig, BffEffectDataPlatformUserConfig, BffEffectOpenApiUserConfig, BffEffectUserConfig, BffRuntimeFramework, } from './bffRuntime.js';
|
|
4
3
|
export interface BffUserConfig {
|
|
5
4
|
prefix?: string | string[];
|
|
6
5
|
httpMethodDecider?: HttpMethodDecider;
|
|
@@ -25,23 +24,13 @@ export interface BffUserConfig {
|
|
|
25
24
|
* Custom request creator import path for generated BFF clients.
|
|
26
25
|
*/
|
|
27
26
|
requestCreator?: string;
|
|
27
|
+
/** Node module exporting a generated-client transform. */
|
|
28
|
+
clientCodegenPlugin?: string;
|
|
28
29
|
/**
|
|
29
30
|
* Legacy custom fetcher import path for generated BFF clients.
|
|
30
31
|
*/
|
|
31
32
|
fetcher?: string;
|
|
32
|
-
/**
|
|
33
|
-
* Selects the BFF runtime implementation.
|
|
34
|
-
*
|
|
35
|
-
* - `effect`: only `api/index` (or the configured `bff.effect.entry`) is served.
|
|
36
|
-
* - `hono`: only `api/lambda/**` handlers are served.
|
|
37
|
-
*
|
|
38
|
-
* @default 'effect'
|
|
39
|
-
*/
|
|
33
|
+
/** Selects a registered BFF runtime implementation. */
|
|
40
34
|
runtimeFramework?: BffRuntimeFramework;
|
|
41
|
-
/**
|
|
42
|
-
* Effect runtime configuration. Only applies when `runtimeFramework: 'effect'`.
|
|
43
|
-
*/
|
|
44
|
-
effect?: BffEffectUserConfig;
|
|
45
|
-
crossProjectPolicy?: BffCrossProjectPolicyUserConfig;
|
|
46
35
|
}
|
|
47
36
|
export type BffNormalizedConfig = BffUserConfig;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import type { SSRMode } from '@modern-js/types';
|
|
2
2
|
import type { WatchOptions } from '@modern-js/utils';
|
|
3
|
-
import type { ServerTelemetryUserConfig } from './serverTelemetry.js';
|
|
4
|
-
export type { ServerTelemetryCanaryAutopilotStateStoreUserConfig, ServerTelemetryCanaryAutopilotUserConfig, ServerTelemetryCanaryContractGateUserConfig, ServerTelemetryCanaryRuntimeFallbackSignalAuthUserConfig, ServerTelemetryCanaryRuntimeFallbackSignalTrustPolicyUserConfig, ServerTelemetryCanaryRuntimeFallbackSignalUserConfig, ServerTelemetryCanaryUserConfig, ServerTelemetryExporterOptions, ServerTelemetrySloUserConfig, ServerTelemetryUserConfig, ServerTelemetryVictoriaMetricsOptions, } from './serverTelemetry.js';
|
|
5
3
|
type Route = string | string[] | {
|
|
6
4
|
route?: string | string[];
|
|
7
5
|
disableSpa?: boolean;
|
|
@@ -50,7 +48,6 @@ export interface ServerUserConfig {
|
|
|
50
48
|
*/
|
|
51
49
|
useJsonScript?: boolean;
|
|
52
50
|
logger?: boolean | Record<string, unknown>;
|
|
53
|
-
telemetry?: ServerTelemetryUserConfig;
|
|
54
51
|
/**
|
|
55
52
|
* @description disable hook middleware for performance
|
|
56
53
|
* @default false
|
|
@@ -66,3 +63,4 @@ export interface ServerUserConfig {
|
|
|
66
63
|
tsconfigPath?: string;
|
|
67
64
|
}
|
|
68
65
|
export type ServerNormalizedConfig = ServerUserConfig;
|
|
66
|
+
export {};
|
|
@@ -1,21 +1,35 @@
|
|
|
1
1
|
import type { AsyncPipelineHook, ServerContext as BaseServerContext, ServerPlugin as BaseServerPlugin, ServerPluginAPI as BaseServerPluginAPI, ServerPluginExtends as BaseServerPluginExtends } from '@modern-js/plugin';
|
|
2
2
|
import type { Hooks } from '@modern-js/plugin/server';
|
|
3
3
|
import type { AfterMatchContext, AfterRenderContext, AfterStreamingRenderContext } from '@modern-js/types';
|
|
4
|
-
import type { MiddlewareHandler } from 'hono';
|
|
4
|
+
import type { Context, MiddlewareHandler } from 'hono';
|
|
5
|
+
import type { ServerStaticPluginOptions } from '../../adapters/node/plugins/static.js';
|
|
5
6
|
import type { APIServerStartInput, MiddlewareObj, ServerConfig, WebAdapter, WebServerStartInput } from './base.js';
|
|
6
7
|
export type PrepareWebServerFn = (input: WebServerStartInput) => Promise<WebAdapter | null>;
|
|
7
8
|
export type PrepareApiServerFn = (input: APIServerStartInput) => Promise<MiddlewareHandler>;
|
|
8
9
|
export type AfterMatchFn = (ctx: AfterMatchContext) => Promise<any>;
|
|
9
10
|
export type AfterRenderFn = (ctx: AfterRenderContext) => Promise<any>;
|
|
10
11
|
export type AfterStreamingRenderContextFn = (ctx: AfterStreamingRenderContext) => Promise<AfterStreamingRenderContext>;
|
|
12
|
+
export interface HandleErrorInput {
|
|
13
|
+
error: Error;
|
|
14
|
+
context: Context;
|
|
15
|
+
response?: Response;
|
|
16
|
+
}
|
|
17
|
+
export type HandleErrorFn = (input: HandleErrorInput, next?: (input: HandleErrorInput) => void) => Promise<HandleErrorInput>;
|
|
11
18
|
export interface ServerPluginExtends extends BaseServerPluginExtends {
|
|
12
19
|
config: ServerConfig;
|
|
20
|
+
extendApi: {
|
|
21
|
+
/** Release an instance resource on shutdown or failed initialization. */
|
|
22
|
+
onDispose: (disposer: () => void | Promise<void>) => () => void;
|
|
23
|
+
};
|
|
13
24
|
extendContext: {
|
|
25
|
+
/** Node static response extensions registered during plugin setup. */
|
|
26
|
+
staticAssetResponders?: ServerStaticPluginOptions;
|
|
14
27
|
middlewares: MiddlewareObj[];
|
|
15
28
|
renderMiddlewares: MiddlewareObj[];
|
|
16
29
|
[key: string]: any;
|
|
17
30
|
};
|
|
18
31
|
extendHooks: {
|
|
32
|
+
handleError: AsyncPipelineHook<HandleErrorFn>;
|
|
19
33
|
prepareWebServer: AsyncPipelineHook<PrepareWebServerFn>;
|
|
20
34
|
prepareApiServer: AsyncPipelineHook<PrepareApiServerFn>;
|
|
21
35
|
afterMatch: AsyncPipelineHook<AfterMatchFn>;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import type { Monitors } from '@modern-js/types';
|
|
2
|
-
export type { SafeFailureEnvelope, SafeFailureHttpResult, } from '@modern-js/runtime-extensions/safe-failure';
|
|
3
|
-
export { createSafeFailureHttpResult, createSafeJsonFailureResponse, getSafeFailureStatus, } from '@modern-js/runtime-extensions/safe-failure';
|
|
4
2
|
export declare const createErrorHtml: (status: number) => string;
|
|
5
3
|
export declare enum ErrorDigest {
|
|
6
4
|
ENOTF = "Page could not be found",
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"modern",
|
|
18
18
|
"modern.js"
|
|
19
19
|
],
|
|
20
|
-
"version": "3.9.0-ultramodern.
|
|
20
|
+
"version": "3.9.0-ultramodern.6",
|
|
21
21
|
"types": "./dist/types/index.d.ts",
|
|
22
22
|
"main": "./dist/cjs/index.js",
|
|
23
23
|
"exports": {
|
|
@@ -66,10 +66,9 @@
|
|
|
66
66
|
"node": ">=20"
|
|
67
67
|
},
|
|
68
68
|
"dependencies": {
|
|
69
|
-
"@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.9.0-ultramodern.
|
|
70
|
-
"@modern-js/runtime-
|
|
71
|
-
"@modern-js/
|
|
72
|
-
"@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.9.0-ultramodern.4",
|
|
69
|
+
"@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.9.0-ultramodern.6",
|
|
70
|
+
"@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.9.0-ultramodern.6",
|
|
71
|
+
"@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.9.0-ultramodern.6",
|
|
73
72
|
"@swc/helpers": "^0.5.23",
|
|
74
73
|
"@web-std/fetch": "^4.2.1",
|
|
75
74
|
"@web-std/file": "^3.0.3",
|
|
@@ -80,7 +79,7 @@
|
|
|
80
79
|
"ts-deepmerge": "8.0.0"
|
|
81
80
|
},
|
|
82
81
|
"devDependencies": {
|
|
83
|
-
"@modern-js/types": "npm:@bleedingdev/modern-js-types@3.9.0-ultramodern.
|
|
82
|
+
"@modern-js/types": "npm:@bleedingdev/modern-js-types@3.9.0-ultramodern.6",
|
|
84
83
|
"@rslib/core": "1.0.0",
|
|
85
84
|
"@scripts/rstest-config": "2.66.0",
|
|
86
85
|
"@types/cloneable-readable": "^2.0.3",
|
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __webpack_require__ = {};
|
|
3
|
-
(()=>{
|
|
4
|
-
__webpack_require__.n = (module)=>{
|
|
5
|
-
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
-
__webpack_require__.d(getter, {
|
|
7
|
-
a: getter
|
|
8
|
-
});
|
|
9
|
-
return getter;
|
|
10
|
-
};
|
|
11
|
-
})();
|
|
12
|
-
(()=>{
|
|
13
|
-
__webpack_require__.d = (exports1, getters, values)=>{
|
|
14
|
-
var define = (defs, kind)=>{
|
|
15
|
-
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
16
|
-
enumerable: true,
|
|
17
|
-
[kind]: defs[key]
|
|
18
|
-
});
|
|
19
|
-
};
|
|
20
|
-
define(getters, "get");
|
|
21
|
-
define(values, "value");
|
|
22
|
-
};
|
|
23
|
-
})();
|
|
24
|
-
(()=>{
|
|
25
|
-
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
26
|
-
})();
|
|
27
|
-
(()=>{
|
|
28
|
-
__webpack_require__.r = (exports1)=>{
|
|
29
|
-
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
30
|
-
value: 'Module'
|
|
31
|
-
});
|
|
32
|
-
Object.defineProperty(exports1, '__esModule', {
|
|
33
|
-
value: true
|
|
34
|
-
});
|
|
35
|
-
};
|
|
36
|
-
})();
|
|
37
|
-
var __webpack_exports__ = {};
|
|
38
|
-
__webpack_require__.r(__webpack_exports__);
|
|
39
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
40
|
-
MODULE_FEDERATION_MANIFEST_FILE: ()=>MODULE_FEDERATION_MANIFEST_FILE,
|
|
41
|
-
applyModuleFederationAssetHeaders: ()=>applyModuleFederationAssetHeaders,
|
|
42
|
-
getModuleFederationAssetList: ()=>getModuleFederationAssetList,
|
|
43
|
-
getModuleFederationRequestPath: ()=>getModuleFederationRequestPath,
|
|
44
|
-
isBackendModuleFederationManifestRequest: ()=>isBackendModuleFederationManifestRequest,
|
|
45
|
-
isModuleFederationManifestRequest: ()=>isModuleFederationManifestRequest,
|
|
46
|
-
patchModuleFederationManifestPublicPath: ()=>patchModuleFederationManifestPublicPath,
|
|
47
|
-
patchModuleFederationRemoteEntryPublicPath: ()=>patchModuleFederationRemoteEntryPublicPath
|
|
48
|
-
});
|
|
49
|
-
const fileReader_namespaceObject = require("@modern-js/runtime-utils/fileReader");
|
|
50
|
-
const utils_namespaceObject = require("@modern-js/utils");
|
|
51
|
-
const external_path_namespaceObject = require("path");
|
|
52
|
-
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
53
|
-
const MODULE_FEDERATION_MANIFEST_FILE = 'mf-manifest.json';
|
|
54
|
-
const BACKEND_MODULE_FEDERATION_MANIFEST_FILE = 'backend-mf-manifest.json';
|
|
55
|
-
const MODULE_FEDERATION_MANIFEST_FILES = [
|
|
56
|
-
MODULE_FEDERATION_MANIFEST_FILE,
|
|
57
|
-
BACKEND_MODULE_FEDERATION_MANIFEST_FILE
|
|
58
|
-
];
|
|
59
|
-
const MODULE_FEDERATION_OPTIONAL_FILES = [
|
|
60
|
-
'mf-stats.json'
|
|
61
|
-
];
|
|
62
|
-
const trimLeadingSlash = (value)=>value.replace(/^\/+/, '');
|
|
63
|
-
const getModuleFederationRequestPath = (pathname, pathPrefix)=>{
|
|
64
|
-
const normalizedPrefix = `/${trimLeadingSlash(pathPrefix)}`.replace(/\/+$/u, '');
|
|
65
|
-
const requestPath = normalizedPrefix && (pathname === normalizedPrefix || pathname.startsWith(`${normalizedPrefix}/`)) ? pathname.slice(normalizedPrefix.length) : pathname;
|
|
66
|
-
return trimLeadingSlash(requestPath);
|
|
67
|
-
};
|
|
68
|
-
const isModuleFederationManifestRequest = (requestPath)=>MODULE_FEDERATION_MANIFEST_FILES.includes(requestPath);
|
|
69
|
-
const isBackendModuleFederationManifestRequest = (requestPath)=>requestPath === BACKEND_MODULE_FEDERATION_MANIFEST_FILE;
|
|
70
|
-
const applyModuleFederationAssetHeaders = (c)=>{
|
|
71
|
-
c.header('Access-Control-Allow-Origin', '*');
|
|
72
|
-
c.header('Access-Control-Allow-Headers', '*');
|
|
73
|
-
c.header('Access-Control-Allow-Methods', 'GET,HEAD,OPTIONS');
|
|
74
|
-
};
|
|
75
|
-
const joinModuleFederationAssetPath = (assetPath, assetName)=>{
|
|
76
|
-
if (!assetName) return '';
|
|
77
|
-
return trimLeadingSlash(external_path_default().posix.join(assetPath || '', assetName));
|
|
78
|
-
};
|
|
79
|
-
const appendModuleFederationAsset = (set, assetPath)=>{
|
|
80
|
-
if (assetPath) set.add(trimLeadingSlash(assetPath));
|
|
81
|
-
};
|
|
82
|
-
const appendModuleFederationAssets = (set, assets)=>{
|
|
83
|
-
assets?.js?.sync?.forEach((asset)=>appendModuleFederationAsset(set, asset));
|
|
84
|
-
assets?.js?.async?.forEach((asset)=>appendModuleFederationAsset(set, asset));
|
|
85
|
-
assets?.css?.sync?.forEach((asset)=>appendModuleFederationAsset(set, asset));
|
|
86
|
-
assets?.css?.async?.forEach((asset)=>appendModuleFederationAsset(set, asset));
|
|
87
|
-
};
|
|
88
|
-
const hasAbsoluteProtocol = (value)=>/^https?:\/\//i.test(value) || value.startsWith('//');
|
|
89
|
-
const ensureLeadingSlash = (value)=>{
|
|
90
|
-
if ('' === value) return '/';
|
|
91
|
-
return value.startsWith('/') ? value : `/${value}`;
|
|
92
|
-
};
|
|
93
|
-
const ensureTrailingSlash = (value)=>value.endsWith('/') ? value : `${value}/`;
|
|
94
|
-
const patchModuleFederationManifestPublicPath = (c, manifestBuffer, pathPrefix)=>{
|
|
95
|
-
try {
|
|
96
|
-
const manifest = JSON.parse(manifestBuffer.toString('utf-8'));
|
|
97
|
-
const publicPath = manifest.metaData?.publicPath;
|
|
98
|
-
if (!publicPath || hasAbsoluteProtocol(publicPath)) return manifestBuffer;
|
|
99
|
-
const requestURL = new URL(c.req.url);
|
|
100
|
-
const prefixPath = ensureTrailingSlash(ensureLeadingSlash(pathPrefix || '/'));
|
|
101
|
-
manifest.metaData = {
|
|
102
|
-
...manifest.metaData,
|
|
103
|
-
publicPath: `${requestURL.origin}${prefixPath}`
|
|
104
|
-
};
|
|
105
|
-
return Buffer.from(JSON.stringify(manifest), 'utf-8');
|
|
106
|
-
} catch {
|
|
107
|
-
return manifestBuffer;
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
const patchModuleFederationRemoteEntryPublicPath = (c, remoteEntryBuffer, pathPrefix)=>{
|
|
111
|
-
const requestURL = new URL(c.req.url);
|
|
112
|
-
const prefixPath = ensureTrailingSlash(ensureLeadingSlash(pathPrefix || '/'));
|
|
113
|
-
const publicPath = `${requestURL.origin}${prefixPath}`;
|
|
114
|
-
const source = remoteEntryBuffer.toString('utf-8');
|
|
115
|
-
const patched = source.replace(/__webpack_require__\.p\s*=\s*(['"`])[^'"`]*\1;/, `__webpack_require__.p = ${JSON.stringify(publicPath)};`).replace(/__rspack_require__\.p\s*=\s*(['"`])[^'"`]*\1;/, `__rspack_require__.p = ${JSON.stringify(publicPath)};`);
|
|
116
|
-
if (patched === source) return remoteEntryBuffer;
|
|
117
|
-
return Buffer.from(patched, 'utf-8');
|
|
118
|
-
};
|
|
119
|
-
const getModuleFederationAssetList = async (pwd)=>{
|
|
120
|
-
const assets = new Set();
|
|
121
|
-
const remoteEntries = new Set();
|
|
122
|
-
let manifestFound = false;
|
|
123
|
-
for (const manifestFile of MODULE_FEDERATION_MANIFEST_FILES){
|
|
124
|
-
const manifestPath = external_path_default().join(pwd, manifestFile);
|
|
125
|
-
if (!await utils_namespaceObject.fs.pathExists(manifestPath)) continue;
|
|
126
|
-
manifestFound = true;
|
|
127
|
-
assets.add(manifestFile);
|
|
128
|
-
const manifestBuffer = await fileReader_namespaceObject.fileReader.readFileFromSystem(manifestPath, 'buffer');
|
|
129
|
-
if (null !== manifestBuffer) try {
|
|
130
|
-
const manifest = JSON.parse(manifestBuffer.toString('utf-8'));
|
|
131
|
-
const remoteEntry = joinModuleFederationAssetPath(manifest.metaData?.remoteEntry?.path, manifest.metaData?.remoteEntry?.name);
|
|
132
|
-
const dtsZip = joinModuleFederationAssetPath(manifest.metaData?.types?.path, manifest.metaData?.types?.zip);
|
|
133
|
-
const dtsApi = joinModuleFederationAssetPath(manifest.metaData?.types?.path, manifest.metaData?.types?.api);
|
|
134
|
-
if (remoteEntry) {
|
|
135
|
-
assets.add(remoteEntry);
|
|
136
|
-
remoteEntries.add(remoteEntry);
|
|
137
|
-
}
|
|
138
|
-
appendModuleFederationAsset(assets, dtsZip);
|
|
139
|
-
appendModuleFederationAsset(assets, dtsApi);
|
|
140
|
-
manifest.shared?.forEach((item)=>appendModuleFederationAssets(assets, item.assets));
|
|
141
|
-
manifest.remotes?.forEach((item)=>appendModuleFederationAssets(assets, item.assets));
|
|
142
|
-
manifest.exposes?.forEach((item)=>appendModuleFederationAssets(assets, item.assets));
|
|
143
|
-
} catch {}
|
|
144
|
-
}
|
|
145
|
-
if (manifestFound) {
|
|
146
|
-
for (const filename of MODULE_FEDERATION_OPTIONAL_FILES)if (await utils_namespaceObject.fs.pathExists(external_path_default().join(pwd, filename))) assets.add(filename);
|
|
147
|
-
}
|
|
148
|
-
return {
|
|
149
|
-
assets,
|
|
150
|
-
remoteEntries
|
|
151
|
-
};
|
|
152
|
-
};
|
|
153
|
-
exports.MODULE_FEDERATION_MANIFEST_FILE = __webpack_exports__.MODULE_FEDERATION_MANIFEST_FILE;
|
|
154
|
-
exports.applyModuleFederationAssetHeaders = __webpack_exports__.applyModuleFederationAssetHeaders;
|
|
155
|
-
exports.getModuleFederationAssetList = __webpack_exports__.getModuleFederationAssetList;
|
|
156
|
-
exports.getModuleFederationRequestPath = __webpack_exports__.getModuleFederationRequestPath;
|
|
157
|
-
exports.isBackendModuleFederationManifestRequest = __webpack_exports__.isBackendModuleFederationManifestRequest;
|
|
158
|
-
exports.isModuleFederationManifestRequest = __webpack_exports__.isModuleFederationManifestRequest;
|
|
159
|
-
exports.patchModuleFederationManifestPublicPath = __webpack_exports__.patchModuleFederationManifestPublicPath;
|
|
160
|
-
exports.patchModuleFederationRemoteEntryPublicPath = __webpack_exports__.patchModuleFederationRemoteEntryPublicPath;
|
|
161
|
-
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
162
|
-
"MODULE_FEDERATION_MANIFEST_FILE",
|
|
163
|
-
"applyModuleFederationAssetHeaders",
|
|
164
|
-
"getModuleFederationAssetList",
|
|
165
|
-
"getModuleFederationRequestPath",
|
|
166
|
-
"isBackendModuleFederationManifestRequest",
|
|
167
|
-
"isModuleFederationManifestRequest",
|
|
168
|
-
"patchModuleFederationManifestPublicPath",
|
|
169
|
-
"patchModuleFederationRemoteEntryPublicPath"
|
|
170
|
-
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
171
|
-
Object.defineProperty(exports, '__esModule', {
|
|
172
|
-
value: true
|
|
173
|
-
});
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __webpack_require__ = {};
|
|
3
|
-
(()=>{
|
|
4
|
-
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
-
var define = (defs, kind)=>{
|
|
6
|
-
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
[kind]: defs[key]
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
define(getters, "get");
|
|
12
|
-
define(values, "value");
|
|
13
|
-
};
|
|
14
|
-
})();
|
|
15
|
-
(()=>{
|
|
16
|
-
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
-
})();
|
|
18
|
-
(()=>{
|
|
19
|
-
__webpack_require__.r = (exports1)=>{
|
|
20
|
-
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
-
value: 'Module'
|
|
22
|
-
});
|
|
23
|
-
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
-
value: true
|
|
25
|
-
});
|
|
26
|
-
};
|
|
27
|
-
})();
|
|
28
|
-
var __webpack_exports__ = {};
|
|
29
|
-
__webpack_require__.r(__webpack_exports__);
|
|
30
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
-
applyPreCompressedAssetHeaders: ()=>applyPreCompressedAssetHeaders,
|
|
32
|
-
resolvePreCompressedAsset: ()=>resolvePreCompressedAsset
|
|
33
|
-
});
|
|
34
|
-
const utils_namespaceObject = require("@modern-js/utils");
|
|
35
|
-
const PRE_COMPRESSED_ASSET_EXTENSIONS = {
|
|
36
|
-
br: '.br',
|
|
37
|
-
gzip: '.gz'
|
|
38
|
-
};
|
|
39
|
-
const PRE_COMPRESSED_SUPPORTED_ENCODINGS = [
|
|
40
|
-
'br',
|
|
41
|
-
'gzip'
|
|
42
|
-
];
|
|
43
|
-
const QUALITY_VALUE_PATTERN = /^(?:0(?:\.\d{0,3})?|1(?:\.0{0,3})?)$/u;
|
|
44
|
-
const parseAcceptEncoding = (value)=>value.split(',').map((item)=>item.trim()).filter(Boolean).map((item)=>{
|
|
45
|
-
const [rawName, ...params] = item.split(';');
|
|
46
|
-
const name = rawName.trim().toLowerCase();
|
|
47
|
-
let q = 1;
|
|
48
|
-
let qualitySeen = false;
|
|
49
|
-
for (const param of params){
|
|
50
|
-
const [key, rawValue] = param.split('=').map((v)=>v.trim());
|
|
51
|
-
if ('q' === key.toLowerCase()) {
|
|
52
|
-
if (qualitySeen || null == rawValue || !QUALITY_VALUE_PATTERN.test(rawValue)) {
|
|
53
|
-
q = 0;
|
|
54
|
-
break;
|
|
55
|
-
}
|
|
56
|
-
qualitySeen = true;
|
|
57
|
-
q = Number(rawValue);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return {
|
|
61
|
-
name,
|
|
62
|
-
q
|
|
63
|
-
};
|
|
64
|
-
});
|
|
65
|
-
const getAcceptedRepresentations = (value)=>{
|
|
66
|
-
if (!value) return [
|
|
67
|
-
'identity'
|
|
68
|
-
];
|
|
69
|
-
const parsed = parseAcceptEncoding(value);
|
|
70
|
-
const qualityByEncoding = new Map();
|
|
71
|
-
let wildcardQuality;
|
|
72
|
-
for (const { name, q } of parsed){
|
|
73
|
-
if ('*' === name) {
|
|
74
|
-
wildcardQuality = q;
|
|
75
|
-
continue;
|
|
76
|
-
}
|
|
77
|
-
qualityByEncoding.set(name, q);
|
|
78
|
-
}
|
|
79
|
-
const getQuality = (encoding)=>{
|
|
80
|
-
const explicit = qualityByEncoding.get(encoding);
|
|
81
|
-
if (void 0 !== explicit) return explicit;
|
|
82
|
-
return wildcardQuality ?? 0;
|
|
83
|
-
};
|
|
84
|
-
const identityQuality = qualityByEncoding.get('identity') ?? (0 === wildcardQuality ? 0 : 1);
|
|
85
|
-
return [
|
|
86
|
-
...PRE_COMPRESSED_SUPPORTED_ENCODINGS.map((encoding)=>({
|
|
87
|
-
encoding,
|
|
88
|
-
quality: getQuality(encoding)
|
|
89
|
-
})),
|
|
90
|
-
{
|
|
91
|
-
encoding: 'identity',
|
|
92
|
-
quality: identityQuality
|
|
93
|
-
}
|
|
94
|
-
].filter((item)=>item.quality > 0).sort((a, b)=>b.quality - a.quality).map((item)=>item.encoding);
|
|
95
|
-
};
|
|
96
|
-
const appendVaryHeader = (c, value)=>{
|
|
97
|
-
const current = c.res.headers.get('Vary');
|
|
98
|
-
if (!current) return void c.header('Vary', value);
|
|
99
|
-
const values = current.split(',').map((item)=>item.trim().toLowerCase()).filter(Boolean);
|
|
100
|
-
if (!values.includes(value.toLowerCase())) c.header('Vary', `${current}, ${value}`);
|
|
101
|
-
};
|
|
102
|
-
const resolvePreCompressedAsset = async (c, filepath)=>{
|
|
103
|
-
const brPath = `${filepath}${PRE_COMPRESSED_ASSET_EXTENSIONS.br}`;
|
|
104
|
-
const gzipPath = `${filepath}${PRE_COMPRESSED_ASSET_EXTENSIONS.gzip}`;
|
|
105
|
-
const [hasBr, hasGzip] = await Promise.all([
|
|
106
|
-
utils_namespaceObject.fs.pathExists(brPath),
|
|
107
|
-
utils_namespaceObject.fs.pathExists(gzipPath)
|
|
108
|
-
]);
|
|
109
|
-
const hasVariant = hasBr || hasGzip;
|
|
110
|
-
const acceptedRepresentations = getAcceptedRepresentations(c.req.header('accept-encoding'));
|
|
111
|
-
for (const encoding of acceptedRepresentations){
|
|
112
|
-
if ('identity' === encoding) return {
|
|
113
|
-
selected: null,
|
|
114
|
-
hasVariant,
|
|
115
|
-
acceptable: true
|
|
116
|
-
};
|
|
117
|
-
if ('br' === encoding && hasBr) return {
|
|
118
|
-
selected: {
|
|
119
|
-
filepath: brPath,
|
|
120
|
-
encoding
|
|
121
|
-
},
|
|
122
|
-
hasVariant: true,
|
|
123
|
-
acceptable: true
|
|
124
|
-
};
|
|
125
|
-
if ('gzip' === encoding && hasGzip) return {
|
|
126
|
-
selected: {
|
|
127
|
-
filepath: gzipPath,
|
|
128
|
-
encoding
|
|
129
|
-
},
|
|
130
|
-
hasVariant: true,
|
|
131
|
-
acceptable: true
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
return {
|
|
135
|
-
selected: null,
|
|
136
|
-
hasVariant,
|
|
137
|
-
acceptable: false
|
|
138
|
-
};
|
|
139
|
-
};
|
|
140
|
-
const applyPreCompressedAssetHeaders = (c, preCompressedAsset)=>{
|
|
141
|
-
if (preCompressedAsset.hasVariant || !preCompressedAsset.acceptable) appendVaryHeader(c, 'Accept-Encoding');
|
|
142
|
-
if (preCompressedAsset.selected) c.header('Content-Encoding', preCompressedAsset.selected.encoding);
|
|
143
|
-
};
|
|
144
|
-
exports.applyPreCompressedAssetHeaders = __webpack_exports__.applyPreCompressedAssetHeaders;
|
|
145
|
-
exports.resolvePreCompressedAsset = __webpack_exports__.resolvePreCompressedAsset;
|
|
146
|
-
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
147
|
-
"applyPreCompressedAssetHeaders",
|
|
148
|
-
"resolvePreCompressedAsset"
|
|
149
|
-
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
150
|
-
Object.defineProperty(exports, '__esModule', {
|
|
151
|
-
value: true
|
|
152
|
-
});
|