c2-http 1.0.24 → 1.0.26

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.
@@ -1,5 +1,6 @@
1
1
  import express, { NextFunction, Request, Response, Router } from "express";
2
2
  export interface IServerConfig {
3
+ openApiFileOutput: any;
3
4
  port: string;
4
5
  globalMiddleware: (app: express.Application) => void;
5
6
  tokenCheckMiddleware: (request: Request, response: Response, next: NextFunction) => void;
@@ -11,5 +12,5 @@ export declare class Server {
11
12
  app: express.Application;
12
13
  config: IServerConfig;
13
14
  constructor(config: IServerConfig);
14
- initialize(callback?: () => void): Promise<void>;
15
+ initialize(callback?: (app: express.Application) => void): Promise<void>;
15
16
  }
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Server = void 0;
7
7
  const express_1 = __importDefault(require("express"));
8
8
  const i18n_1 = require("../i18n");
9
+ const swagger_ui_express_1 = __importDefault(require("swagger-ui-express"));
9
10
  class Server {
10
11
  app;
11
12
  config;
@@ -16,6 +17,9 @@ class Server {
16
17
  async initialize(callback) {
17
18
  (0, i18n_1.initializei18n)(this.config.i18n);
18
19
  console.log(`Initializing server on ${this.config.port}...`);
20
+ if (this.config.openApiFileOutput) {
21
+ this.app.use("/docs", swagger_ui_express_1.default.serve, swagger_ui_express_1.default.setup(this.config.openApiFileOutput));
22
+ }
19
23
  this.config.globalMiddleware(this.app);
20
24
  for (const router of this.config.routes) {
21
25
  this.app.use(router);
@@ -27,7 +31,7 @@ class Server {
27
31
  this.app.listen(this.config.port, async () => {
28
32
  console.info(`Server running on port ${this.config.port}`);
29
33
  if (callback) {
30
- await callback();
34
+ await callback(this.app);
31
35
  }
32
36
  });
33
37
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-http",
3
- "version": "1.0.24",
3
+ "version": "1.0.26",
4
4
  "description": "Biblioteca Typescript para API NodeJS",
5
5
  "repository": "https://cabralsilva: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@github.com/cabralsilva/c2-http.git",
6
6
  "author": "Daniel Cabral <cabralconsultoriaemsoftware@gmail.com>",
@@ -23,6 +23,7 @@
23
23
  "@types/express": "^4.17.21",
24
24
  "@types/http-status": "^1.1.2",
25
25
  "@types/mongoose": "^5.11.97",
26
+ "@types/swagger-ui-express": "^4.1.6",
26
27
  "axios": "^1.6.8",
27
28
  "c2-util": "^1.0.13",
28
29
  "express": "^4.19.2",
@@ -30,6 +31,8 @@
30
31
  "express-rest-i18n": "^1.0.1",
31
32
  "http-status": "^1.7.4",
32
33
  "mongoose": "^8.3.4",
34
+ "swagger-autogen": "^2.23.7",
35
+ "swagger-ui-express": "^5.0.0",
33
36
  "ts-node": "^10.8.1",
34
37
  "typescript": "^4.7.4"
35
38
  },