imean-service-engine 2.0.1 → 2.0.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/dist/index.d.mts +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +3 -1
- package/dist/index.mjs +3 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -393,6 +393,12 @@ interface RouteModuleOptions {
|
|
|
393
393
|
* RoutePlugin 配置选项
|
|
394
394
|
*/
|
|
395
395
|
interface RoutePluginOptions {
|
|
396
|
+
/**
|
|
397
|
+
* 全局路径前缀(应用于所有路由)
|
|
398
|
+
* 路径拼接顺序:全局前缀 + 模块前缀 + 路由路径
|
|
399
|
+
* 例如:prefix="/api", routePrefix="/v1", path="/users" => "/api/v1/users"
|
|
400
|
+
*/
|
|
401
|
+
prefix?: string;
|
|
396
402
|
/**
|
|
397
403
|
* 全局中间件(应用于所有路由)
|
|
398
404
|
* 执行顺序:全局中间件 -> 模块级中间件 -> 路由级中间件
|
|
@@ -441,13 +447,14 @@ declare function Page(options: RouteOptions): (target: Function, context: ClassM
|
|
|
441
447
|
*
|
|
442
448
|
* @example
|
|
443
449
|
* ```typescript
|
|
444
|
-
* //
|
|
450
|
+
* // 使用全局前缀和中间件
|
|
445
451
|
* const authMiddleware = async (ctx, next) => {
|
|
446
452
|
* // 验证 token
|
|
447
453
|
* await next();
|
|
448
454
|
* };
|
|
449
455
|
*
|
|
450
456
|
* const routePlugin = new RoutePlugin({
|
|
457
|
+
* prefix: "/api", // 全局路径前缀,所有路由都会加上这个前缀
|
|
451
458
|
* globalMiddlewares: [authMiddleware],
|
|
452
459
|
* });
|
|
453
460
|
* ```
|
|
@@ -456,6 +463,7 @@ declare class RoutePlugin implements Plugin<RouteModuleOptions> {
|
|
|
456
463
|
readonly name = "route-plugin";
|
|
457
464
|
readonly priority = PluginPriority.ROUTE;
|
|
458
465
|
private engine;
|
|
466
|
+
private globalPrefix;
|
|
459
467
|
private globalMiddlewares;
|
|
460
468
|
/**
|
|
461
469
|
* 构造函数
|
package/dist/index.d.ts
CHANGED
|
@@ -393,6 +393,12 @@ interface RouteModuleOptions {
|
|
|
393
393
|
* RoutePlugin 配置选项
|
|
394
394
|
*/
|
|
395
395
|
interface RoutePluginOptions {
|
|
396
|
+
/**
|
|
397
|
+
* 全局路径前缀(应用于所有路由)
|
|
398
|
+
* 路径拼接顺序:全局前缀 + 模块前缀 + 路由路径
|
|
399
|
+
* 例如:prefix="/api", routePrefix="/v1", path="/users" => "/api/v1/users"
|
|
400
|
+
*/
|
|
401
|
+
prefix?: string;
|
|
396
402
|
/**
|
|
397
403
|
* 全局中间件(应用于所有路由)
|
|
398
404
|
* 执行顺序:全局中间件 -> 模块级中间件 -> 路由级中间件
|
|
@@ -441,13 +447,14 @@ declare function Page(options: RouteOptions): (target: Function, context: ClassM
|
|
|
441
447
|
*
|
|
442
448
|
* @example
|
|
443
449
|
* ```typescript
|
|
444
|
-
* //
|
|
450
|
+
* // 使用全局前缀和中间件
|
|
445
451
|
* const authMiddleware = async (ctx, next) => {
|
|
446
452
|
* // 验证 token
|
|
447
453
|
* await next();
|
|
448
454
|
* };
|
|
449
455
|
*
|
|
450
456
|
* const routePlugin = new RoutePlugin({
|
|
457
|
+
* prefix: "/api", // 全局路径前缀,所有路由都会加上这个前缀
|
|
451
458
|
* globalMiddlewares: [authMiddleware],
|
|
452
459
|
* });
|
|
453
460
|
* ```
|
|
@@ -456,6 +463,7 @@ declare class RoutePlugin implements Plugin<RouteModuleOptions> {
|
|
|
456
463
|
readonly name = "route-plugin";
|
|
457
464
|
readonly priority = PluginPriority.ROUTE;
|
|
458
465
|
private engine;
|
|
466
|
+
private globalPrefix;
|
|
459
467
|
private globalMiddlewares;
|
|
460
468
|
/**
|
|
461
469
|
* 构造函数
|
package/dist/index.js
CHANGED
|
@@ -2124,12 +2124,14 @@ var RoutePlugin = class {
|
|
|
2124
2124
|
name = "route-plugin";
|
|
2125
2125
|
priority = 1e3 /* ROUTE */;
|
|
2126
2126
|
engine;
|
|
2127
|
+
globalPrefix;
|
|
2127
2128
|
globalMiddlewares;
|
|
2128
2129
|
/**
|
|
2129
2130
|
* 构造函数
|
|
2130
2131
|
* @param options 插件配置选项
|
|
2131
2132
|
*/
|
|
2132
2133
|
constructor(options) {
|
|
2134
|
+
this.globalPrefix = options?.prefix || "";
|
|
2133
2135
|
this.globalMiddlewares = options?.globalMiddlewares || [];
|
|
2134
2136
|
}
|
|
2135
2137
|
/**
|
|
@@ -2182,7 +2184,7 @@ var RoutePlugin = class {
|
|
|
2182
2184
|
const moduleOptions = moduleMetadata?.options || {};
|
|
2183
2185
|
const routePrefix = moduleOptions.routePrefix || "";
|
|
2184
2186
|
const paths = Array.isArray(routeOptions.path) ? routeOptions.path : [routeOptions.path];
|
|
2185
|
-
const fullPaths = paths.map((p) => routePrefix + p);
|
|
2187
|
+
const fullPaths = paths.map((p) => this.globalPrefix + routePrefix + p);
|
|
2186
2188
|
const routeHandler = async (ctx) => {
|
|
2187
2189
|
const method = moduleInstance[methodName];
|
|
2188
2190
|
if (typeof method !== "function") {
|
package/dist/index.mjs
CHANGED
|
@@ -2099,12 +2099,14 @@ var RoutePlugin = class {
|
|
|
2099
2099
|
name = "route-plugin";
|
|
2100
2100
|
priority = 1e3 /* ROUTE */;
|
|
2101
2101
|
engine;
|
|
2102
|
+
globalPrefix;
|
|
2102
2103
|
globalMiddlewares;
|
|
2103
2104
|
/**
|
|
2104
2105
|
* 构造函数
|
|
2105
2106
|
* @param options 插件配置选项
|
|
2106
2107
|
*/
|
|
2107
2108
|
constructor(options) {
|
|
2109
|
+
this.globalPrefix = options?.prefix || "";
|
|
2108
2110
|
this.globalMiddlewares = options?.globalMiddlewares || [];
|
|
2109
2111
|
}
|
|
2110
2112
|
/**
|
|
@@ -2157,7 +2159,7 @@ var RoutePlugin = class {
|
|
|
2157
2159
|
const moduleOptions = moduleMetadata?.options || {};
|
|
2158
2160
|
const routePrefix = moduleOptions.routePrefix || "";
|
|
2159
2161
|
const paths = Array.isArray(routeOptions.path) ? routeOptions.path : [routeOptions.path];
|
|
2160
|
-
const fullPaths = paths.map((p) => routePrefix + p);
|
|
2162
|
+
const fullPaths = paths.map((p) => this.globalPrefix + routePrefix + p);
|
|
2161
2163
|
const routeHandler = async (ctx) => {
|
|
2162
2164
|
const method = moduleInstance[methodName];
|
|
2163
2165
|
if (typeof method !== "function") {
|