@rdyl/node-koa-controller 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,4 +1,4 @@
1
- ## 0.0.2 (2025-03-12)
1
+ ## 0.0.2 (2025-03-28)
2
2
 
3
3
 
4
4
 
@@ -81,6 +81,7 @@ var koa_router_1 = __importDefault(require("koa-router"));
81
81
  var fs_1 = __importDefault(require("fs"));
82
82
  var path_1 = require("path");
83
83
  exports.ASTCache = {
84
+ prefix: "",
84
85
  routes: [],
85
86
  whitelist: [],
86
87
  };
@@ -89,10 +90,10 @@ function RegisterASTCacheRoutes(router) {
89
90
  var handlers = route.handlers, prefix = route.prefix, Instance = route.Instance;
90
91
  handlers.forEach(function (handler) {
91
92
  var method = handler.method, url = handler.url, name = handler.name;
92
- var path = (0, path_1.join)('/' + prefix, url);
93
+ var path = (0, path_1.join)("/" + prefix, url);
93
94
  var isPublic = route.isPublic || route.isPublic;
94
95
  if (isPublic) {
95
- exports.ASTCache.whitelist.push(path);
96
+ exports.ASTCache.whitelist.push((0, path_1.join)("/" + exports.ASTCache.prefix, path));
96
97
  }
97
98
  // @ts-ignore
98
99
  router[method.toLowerCase()](path, function (_ctx) {
@@ -101,7 +102,7 @@ function RegisterASTCacheRoutes(router) {
101
102
  instance[name]();
102
103
  }
103
104
  catch (_a) {
104
- console.log(path + ':配置错误!');
105
+ console.log(path + ":配置错误!");
105
106
  }
106
107
  });
107
108
  });
@@ -111,10 +112,11 @@ function useController(app_1, _a) {
111
112
  return __awaiter(this, arguments, void 0, function (app, _b) {
112
113
  var router, rootDir, initAST;
113
114
  var _this = this;
114
- var root = _b.root, _c = _b.prefix, prefix = _c === void 0 ? '' : _c;
115
+ var root = _b.root, _c = _b.prefix, prefix = _c === void 0 ? "" : _c;
115
116
  return __generator(this, function (_d) {
116
117
  switch (_d.label) {
117
118
  case 0:
119
+ exports.ASTCache.prefix = prefix;
118
120
  router = new koa_router_1.default({
119
121
  prefix: prefix,
120
122
  });
@@ -142,9 +144,9 @@ function useController(app_1, _a) {
142
144
  return [3 /*break*/, 7];
143
145
  case 3:
144
146
  _b.trys.push([3, 6, , 7]);
145
- sp = p.split('.');
147
+ sp = p.split(".");
146
148
  ext = sp[sp.length - 1];
147
- if (!(ext === 'ts' || ext === 'js')) return [3 /*break*/, 5];
149
+ if (!(ext === "ts" || ext === "js")) return [3 /*break*/, 5];
148
150
  // ts | js 文件
149
151
  return [4 /*yield*/, Promise.resolve("".concat(url)).then(function (s) { return __importStar(require(s)); })];
150
152
  case 4:
@@ -154,7 +156,7 @@ function useController(app_1, _a) {
154
156
  case 5: return [3 /*break*/, 7];
155
157
  case 6:
156
158
  _a = _b.sent();
157
- console.warn('解析出现错误!');
159
+ console.warn("解析出现错误!");
158
160
  return [3 /*break*/, 7];
159
161
  case 7:
160
162
  _i++;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rdyl/node-koa-controller",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "types/index.d.ts",
@@ -1,7 +1,7 @@
1
- import Koa from 'koa';
2
- import { ASTCacheProp, InitOpts } from './meta';
1
+ import Koa from "koa";
2
+ import { ASTCacheProp, InitOpts } from "./meta";
3
3
  export declare const ASTCache: ASTCacheProp;
4
4
  export declare function useController(app: Koa, { root, prefix }: InitOpts): Promise<{
5
5
  whitelist: string[];
6
6
  }>;
7
- export * from './meta';
7
+ export * from "./meta";
@@ -54,6 +54,7 @@ export interface ASTCacheRoute {
54
54
  handlers: ASTCacheHandler[];
55
55
  }
56
56
  export interface ASTCacheProp {
57
+ prefix: string;
57
58
  routes: ASTCacheRoute[];
58
59
  whitelist: string[];
59
60
  }