@rdyl/node-koa-controller 0.0.4 → 0.0.5

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.4 (2025-03-28)
1
+ ## 0.0.4 (2025-04-02)
2
2
 
3
3
 
4
4
 
@@ -78,6 +78,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
78
78
  exports.ASTCache = void 0;
79
79
  exports.useController = useController;
80
80
  var koa_router_1 = __importDefault(require("koa-router"));
81
+ var koa_static_1 = __importDefault(require("koa-static"));
81
82
  var fs_1 = __importDefault(require("fs"));
82
83
  var path_1 = require("path");
83
84
  exports.ASTCache = {
@@ -108,14 +109,14 @@ function RegisterASTCacheRoutes(router) {
108
109
  });
109
110
  });
110
111
  }
111
- function useController(app_1, _a) {
112
- return __awaiter(this, arguments, void 0, function (app, _b) {
113
- var router, rootDir, initAST;
112
+ function useController(app, opts) {
113
+ return __awaiter(this, void 0, void 0, function () {
114
+ var root, _a, prefix, router, rootDir, initAST;
114
115
  var _this = this;
115
- var root = _b.root, _c = _b.prefix, prefix = _c === void 0 ? "" : _c;
116
- return __generator(this, function (_d) {
117
- switch (_d.label) {
116
+ return __generator(this, function (_b) {
117
+ switch (_b.label) {
118
118
  case 0:
119
+ root = opts.root, _a = opts.prefix, prefix = _a === void 0 ? "" : _a;
119
120
  exports.ASTCache.prefix = prefix;
120
121
  router = new koa_router_1.default();
121
122
  rootDir = (0, path_1.resolve)(process.cwd(), root);
@@ -165,9 +166,15 @@ function useController(app_1, _a) {
165
166
  }); };
166
167
  return [4 /*yield*/, initAST(rootDir)];
167
168
  case 1:
168
- _d.sent();
169
+ _b.sent();
169
170
  // 注册路由
170
171
  RegisterASTCacheRoutes(router);
172
+ if (opts.static) {
173
+ app.use((0, koa_static_1.default)(process.cwd(), {
174
+ root: opts.static,
175
+ }));
176
+ exports.ASTCache.whitelist.unshift(new RegExp("/".concat(opts.static)));
177
+ }
171
178
  app.use(router.routes()).use(router.allowedMethods());
172
179
  return [2 /*return*/, Promise.resolve({
173
180
  whitelist: exports.ASTCache.whitelist,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rdyl/node-koa-controller",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "types/index.d.ts",
@@ -20,15 +20,17 @@
20
20
  "dependencies": {
21
21
  "@types/koa": "^2.15.0",
22
22
  "@types/koa-router": "^7.4.8",
23
+ "@types/koa-static": "^4.0.4",
23
24
  "koa": "^2.15.3",
24
- "koa-router": "^13.0.1"
25
+ "koa-router": "^13.0.1",
26
+ "koa-static": "^5.0.0"
25
27
  },
26
28
  "devDependencies": {
27
- "@types/node": "^22.9.0",
28
- "copyfiles": "^2.4.1",
29
- "typescript": "^5.6.3",
30
29
  "@commitlint/cli": "^19.6.1",
31
30
  "@commitlint/config-conventional": "^19.6.0",
32
- "conventional-changelog-cli": "^5.0.0"
31
+ "@types/node": "^22.9.0",
32
+ "conventional-changelog-cli": "^5.0.0",
33
+ "copyfiles": "^2.4.1",
34
+ "typescript": "^5.6.3"
33
35
  }
34
- }
36
+ }
@@ -1,7 +1,7 @@
1
1
  import Koa from "koa";
2
- import { ASTCacheProp, InitOpts } from "./meta";
2
+ import { ASTCacheProp, UseProps } from "./meta";
3
3
  export declare const ASTCache: ASTCacheProp;
4
- export declare function useController(app: Koa, { root, prefix }: InitOpts): Promise<{
5
- whitelist: string[];
4
+ export declare function useController(app: Koa, opts: UseProps): Promise<{
5
+ whitelist: (string | RegExp)[];
6
6
  }>;
7
7
  export * from "./meta";
@@ -37,9 +37,10 @@ export interface ResData<T> {
37
37
  code: number;
38
38
  data: T;
39
39
  }
40
- export interface InitOpts {
40
+ export interface UseProps {
41
41
  root: string;
42
42
  prefix?: string;
43
+ static?: string;
43
44
  }
44
45
  export interface ASTCacheHandler {
45
46
  url: string;
@@ -56,5 +57,5 @@ export interface ASTCacheRoute {
56
57
  export interface ASTCacheProp {
57
58
  prefix: string;
58
59
  routes: ASTCacheRoute[];
59
- whitelist: string[];
60
+ whitelist: (string | RegExp)[];
60
61
  }