@rdyl/node-koa-controller 0.1.4 → 0.1.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.1.4 (2025-04-10)
1
+ ## 0.1.5 (2025-04-10)
2
2
 
3
3
 
4
4
 
@@ -140,12 +140,12 @@ function RegisterASTCacheRoutes(router, useJwt) {
140
140
  }
141
141
  function useController(app, opts) {
142
142
  return __awaiter(this, void 0, void 0, function () {
143
- var root, _a, prefix, _b, logs, formidable, useJwt, router, rootDir, initAST;
143
+ var root, _a, prefix, _b, port, _c, logs, formidable, useJwt, router, rootDir, initAST, ip;
144
144
  var _this = this;
145
- return __generator(this, function (_c) {
146
- switch (_c.label) {
145
+ return __generator(this, function (_d) {
146
+ switch (_d.label) {
147
147
  case 0:
148
- root = opts.root, _a = opts.prefix, prefix = _a === void 0 ? "" : _a, _b = opts.logs, logs = _b === void 0 ? true : _b, formidable = opts.formidable, useJwt = opts.useJwt;
148
+ root = opts.root, _a = opts.prefix, prefix = _a === void 0 ? "" : _a, _b = opts.port, port = _b === void 0 ? 8080 : _b, _c = opts.logs, logs = _c === void 0 ? true : _c, formidable = opts.formidable, useJwt = opts.useJwt;
149
149
  exports.ASTCache.prefix = prefix;
150
150
  router = new koa_router_1.default();
151
151
  rootDir = (0, path_1.resolve)(process.cwd(), root);
@@ -195,7 +195,7 @@ function useController(app, opts) {
195
195
  }); };
196
196
  return [4 /*yield*/, initAST(rootDir)];
197
197
  case 1:
198
- _c.sent();
198
+ _d.sent();
199
199
  // 注册路由
200
200
  RegisterASTCacheRoutes(router, useJwt);
201
201
  if (opts.static) {
@@ -253,9 +253,20 @@ function useController(app, opts) {
253
253
  }); });
254
254
  }
255
255
  app.use(router.routes()).use(router.allowedMethods());
256
- return [2 /*return*/, Promise.resolve({
256
+ ip = (0, utils_1.getIPAdress)();
257
+ return [2 /*return*/, {
257
258
  whitelist: exports.ASTCache.whitelist,
258
- })];
259
+ port: port,
260
+ prefix: prefix,
261
+ ip: ip,
262
+ running: function () {
263
+ return (0, utils_1.RunningLogs)({
264
+ ip: ip,
265
+ port: port,
266
+ prefix: prefix,
267
+ });
268
+ },
269
+ }];
259
270
  }
260
271
  });
261
272
  });
@@ -1,6 +1,15 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.formatDateTime = formatDateTime;
7
+ exports.getIPAdress = getIPAdress;
8
+ exports.RunningLogs = RunningLogs;
9
+ var os_1 = __importDefault(require("os"));
10
+ var path_1 = require("path");
11
+ var boxen_1 = __importDefault(require("boxen"));
12
+ var chalk_1 = __importDefault(require("chalk"));
4
13
  function formatDateTime(date, format) {
5
14
  if (date === void 0) { date = new Date(); }
6
15
  if (format === void 0) { format = "YYYY-MM-DD HH:mm:ss"; }
@@ -19,3 +28,33 @@ function formatDateTime(date, format) {
19
28
  .replace("mm", minutes)
20
29
  .replace("ss", seconds);
21
30
  }
31
+ function getIPAdress() {
32
+ var interfaces = os_1.default.networkInterfaces();
33
+ for (var key in interfaces) {
34
+ var iface = interfaces[key];
35
+ if (iface) {
36
+ for (var i = 0; i < iface.length; i++) {
37
+ var alias = iface[i];
38
+ if (alias.family === "IPv4" &&
39
+ alias.address !== "127.0.0.1" &&
40
+ !alias.internal) {
41
+ return alias.address;
42
+ }
43
+ }
44
+ }
45
+ }
46
+ return "127.0.0.1";
47
+ }
48
+ function RunningLogs(config) {
49
+ var port = config.port, prefix = config.prefix, ip = config.ip;
50
+ var suffix = (0, path_1.join)(port.toString(), prefix);
51
+ var env = process.env.NODE_ENV || "development";
52
+ var messages = (0, boxen_1.default)(chalk_1.default.hex("#83FFE6")("\n ".concat(chalk_1.default.bold.hex("#FFA500")("🚀 Server started successfully!"), "\n\n ").concat(chalk_1.default.bold("Env:"), " ").concat(chalk_1.default.white(" " + env + " "), "\n\n ").concat(chalk_1.default.bold("Local:"), " ").concat(chalk_1.default.green("http://localhost:".concat(suffix)), "\n ").concat(chalk_1.default.bold("Network:"), " ").concat(chalk_1.default.green("http://".concat(ip, ":").concat(suffix)), "\n")), {
53
+ padding: 0.5,
54
+ margin: 0.5,
55
+ borderStyle: "round",
56
+ borderColor: "#5ED7FF",
57
+ });
58
+ console.clear();
59
+ console.log(messages);
60
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rdyl/node-koa-controller",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "types/index.d.ts",
@@ -21,6 +21,7 @@
21
21
  "@types/koa": "^2.15.0",
22
22
  "@types/koa-router": "^7.4.8",
23
23
  "@types/koa-static": "^4.0.4",
24
+ "boxen": "^8.0.1",
24
25
  "chalk": "^5.4.1",
25
26
  "koa": "^2.15.3",
26
27
  "koa-body": "^6.0.1",
@@ -1,7 +1,5 @@
1
1
  import Koa from "koa";
2
- import { ASTCacheProp, UseProps } from "./meta";
2
+ import { ASTCacheProp, SyncUseValue, UseProps } from "./meta";
3
3
  export declare const ASTCache: ASTCacheProp;
4
- export declare function useController(app: Koa, opts: UseProps): Promise<{
5
- whitelist: (string | RegExp)[];
6
- }>;
4
+ export declare function useController(app: Koa, opts: UseProps): Promise<SyncUseValue>;
7
5
  export * from "./meta";
@@ -51,6 +51,7 @@ export interface ResData<T> {
51
51
  data?: T | null;
52
52
  }
53
53
  export interface UseProps {
54
+ port: number;
54
55
  root: string;
55
56
  prefix?: string;
56
57
  static?: string;
@@ -61,6 +62,13 @@ export interface UseProps {
61
62
  get(n: string): Promise<UseJwtValue>;
62
63
  };
63
64
  }
65
+ export interface SyncUseValue {
66
+ port: number;
67
+ prefix: string;
68
+ whitelist: (string | RegExp)[];
69
+ ip: string;
70
+ running(): unknown;
71
+ }
64
72
  export interface ASTCacheHandler {
65
73
  url: string;
66
74
  method: string;
@@ -1 +1,7 @@
1
1
  export declare function formatDateTime(date?: Date, format?: string): string;
2
+ export declare function getIPAdress(): string;
3
+ export declare function RunningLogs(config: {
4
+ port: number;
5
+ prefix: string;
6
+ ip: string;
7
+ }): void;