c2-http 1.0.23 → 1.0.25

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.js CHANGED
@@ -33,7 +33,7 @@ const convertErrorToHttpError = (error) => {
33
33
  return new HttpError_1.HttpError(http_status_1.NOT_ACCEPTABLE, (0, i18n_1.getMessage)("message.fieldIsRequired", fields.join(", ")), error.errors);
34
34
  }
35
35
  if (axios_1.default.isAxiosError(error)) {
36
- return new HttpError_1.HttpError(error.response?.status, error.message, error.response?.data);
36
+ return new HttpError_1.HttpError(error.response?.status, error.message, error.response);
37
37
  }
38
38
  if (error instanceof HttpError_1.HttpError) {
39
39
  return error;
@@ -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;
@@ -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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-http",
3
- "version": "1.0.23",
3
+ "version": "1.0.25",
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
  },