c2-http 1.0.13 → 1.0.15

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.d.ts CHANGED
@@ -4,5 +4,6 @@ import { CrudController } from "./model/CrudController";
4
4
  import { HttpError } from "./model/HttpError";
5
5
  import { IControllerOptions } from "./model/IControllerOptions";
6
6
  import { ICrudControllerOptions } from "./model/ICrudControllerOptions";
7
+ import { Server, IServerConfig } from "./model/Server";
7
8
  export declare const convertErrorToHttpError: (error: any) => HttpError;
8
- export { Controller, CrudController, IControllerOptions, ICrudControllerOptions, HttpDispatchDownload, HttpDispatchHandling, getMessage, initializei18n };
9
+ export { Controller, CrudController, IControllerOptions, ICrudControllerOptions, Server, IServerConfig, HttpDispatchDownload, HttpDispatchHandling, getMessage, initializei18n };
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.initializei18n = exports.getMessage = exports.HttpDispatchHandling = exports.HttpDispatchDownload = exports.CrudController = exports.Controller = exports.convertErrorToHttpError = void 0;
6
+ exports.initializei18n = exports.getMessage = exports.HttpDispatchHandling = exports.HttpDispatchDownload = exports.Server = exports.CrudController = exports.Controller = exports.convertErrorToHttpError = void 0;
7
7
  const express_http_context_1 = __importDefault(require("express-http-context"));
8
8
  const http_status_1 = require("http-status");
9
9
  const mongodb_1 = require("mongodb");
@@ -18,6 +18,8 @@ Object.defineProperty(exports, "HttpDispatchHandling", { enumerable: true, get:
18
18
  const CrudController_1 = require("./model/CrudController");
19
19
  Object.defineProperty(exports, "CrudController", { enumerable: true, get: function () { return CrudController_1.CrudController; } });
20
20
  const HttpError_1 = require("./model/HttpError");
21
+ const Server_1 = require("./model/Server");
22
+ Object.defineProperty(exports, "Server", { enumerable: true, get: function () { return Server_1.Server; } });
21
23
  const convertErrorToHttpError = (error) => {
22
24
  if (error instanceof mongodb_1.MongoServerError) {
23
25
  if (error.code === 11000) {
@@ -0,0 +1,11 @@
1
+ import express, { NextFunction, Router } from "express";
2
+ export interface IServerConfig {
3
+ globalMiddleware: (app: express.Application) => void;
4
+ tokenCheckMiddleware: (request: Request, response: Response, next: NextFunction) => void;
5
+ routesWithToken: Router[];
6
+ routes: Router[];
7
+ }
8
+ export declare class Server {
9
+ app: express.Application;
10
+ constructor(config: IServerConfig);
11
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Server = void 0;
7
+ const express_1 = __importDefault(require("express"));
8
+ class Server {
9
+ app;
10
+ constructor(config) {
11
+ this.app = (0, express_1.default)();
12
+ config.globalMiddleware(this.app);
13
+ for (const router of config.routes) {
14
+ this.app.use(router);
15
+ }
16
+ config.tokenCheckMiddleware;
17
+ for (const router of config.routesWithToken) {
18
+ this.app.use(router);
19
+ }
20
+ }
21
+ }
22
+ exports.Server = Server;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-http",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
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>",