c2-http 1.0.18 → 1.0.21

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/i18n.js CHANGED
@@ -16,7 +16,9 @@ let i18n = i18nCreate({
16
16
  }
17
17
  });
18
18
  const initializei18n = (config) => {
19
+ console.log("Initializing i18n...");
19
20
  i18n = i18nCreate(config);
21
+ console.log("Done i18n");
20
22
  };
21
23
  exports.initializei18n = initializei18n;
22
24
  const getMessage = (message, ...parameters) => {
package/dist/index.js CHANGED
@@ -20,6 +20,7 @@ Object.defineProperty(exports, "CrudController", { enumerable: true, get: functi
20
20
  const HttpError_1 = require("./model/HttpError");
21
21
  const Server_1 = require("./model/Server");
22
22
  Object.defineProperty(exports, "Server", { enumerable: true, get: function () { return Server_1.Server; } });
23
+ const axios_1 = require("axios");
23
24
  const convertErrorToHttpError = (error) => {
24
25
  if (error instanceof mongodb_1.MongoServerError) {
25
26
  if (error.code === 11000) {
@@ -31,6 +32,9 @@ const convertErrorToHttpError = (error) => {
31
32
  const fields = Object.keys(error.errors);
32
33
  return new HttpError_1.HttpError(http_status_1.NOT_ACCEPTABLE, (0, i18n_1.getMessage)("message.fieldIsRequired", fields.join(", ")), error.errors);
33
34
  }
35
+ if (error instanceof axios_1.AxiosError) {
36
+ return new HttpError_1.HttpError(error.status, error.message, error.response?.data);
37
+ }
34
38
  if (error instanceof HttpError_1.HttpError) {
35
39
  return error;
36
40
  }
@@ -1,14 +1,15 @@
1
- import express, { Request, Response, NextFunction, Router } from "express";
1
+ import express, { NextFunction, Request, Response, Router } from "express";
2
2
  export interface IServerConfig {
3
3
  port: string;
4
4
  globalMiddleware: (app: express.Application) => void;
5
5
  tokenCheckMiddleware: (request: Request, response: Response, next: NextFunction) => void;
6
6
  routesWithToken: Router[];
7
7
  routes: Router[];
8
+ i18n: any;
8
9
  }
9
10
  export declare class Server {
10
11
  app: express.Application;
11
12
  config: IServerConfig;
12
13
  constructor(config: IServerConfig);
13
- initialize(): Promise<void>;
14
+ initialize(callback?: () => void): Promise<void>;
14
15
  }
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Server = void 0;
7
7
  const express_1 = __importDefault(require("express"));
8
+ const i18n_1 = require("../i18n");
8
9
  class Server {
9
10
  app;
10
11
  config;
@@ -12,23 +13,9 @@ class Server {
12
13
  this.app = (0, express_1.default)();
13
14
  this.config = config;
14
15
  }
15
- async initialize() {
16
- // const port = httpPort || "8085";
17
- // console.info(`Server starting... on port ${port}`);
18
- // await Database.createConnection()
19
- // initializei18n({
20
- // defaultLocale: "pt-br",
21
- // warn: false, // optional
22
- // allowFallback: true, // optional
23
- // messages: {
24
- // "en": en,
25
- // "en-US": en,
26
- // "en_US": en,
27
- // "pt": pt_BR,
28
- // "pt-br": pt_BR,
29
- // "pt_BR": pt_BR
30
- // }
31
- // })
16
+ async initialize(callback) {
17
+ (0, i18n_1.initializei18n)(this.config.i18n);
18
+ console.log(`Initializing server on ${this.config.port}...`);
32
19
  this.config.globalMiddleware(this.app);
33
20
  for (const router of this.config.routes) {
34
21
  this.app.use(router);
@@ -37,8 +24,11 @@ class Server {
37
24
  for (const router of this.config.routesWithToken) {
38
25
  this.app.use(router);
39
26
  }
40
- this.app.listen(this.config.port, () => {
27
+ this.app.listen(this.config.port, async () => {
41
28
  console.info(`Server running on port ${this.config.port}`);
29
+ if (callback) {
30
+ await callback();
31
+ }
42
32
  });
43
33
  }
44
34
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-http",
3
- "version": "1.0.18",
3
+ "version": "1.0.21",
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>",
@@ -19,9 +19,11 @@
19
19
  "publish-major": "npm version major"
20
20
  },
21
21
  "dependencies": {
22
+ "@types/axios": "^0.14.0",
22
23
  "@types/express": "^4.17.21",
23
24
  "@types/http-status": "^1.1.2",
24
25
  "@types/mongoose": "^5.11.97",
26
+ "axios": "^1.6.8",
25
27
  "c2-util": "^1.0.13",
26
28
  "express": "^4.19.2",
27
29
  "express-http-context": "^1.2.4",