-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from ElArteDelCodigo/develop
Estructura inicial
- Loading branch information
Showing
30 changed files
with
3,877 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"ecmaVersion": "latest", | ||
"sourceType": "module" | ||
}, | ||
"plugins": ["@typescript-eslint", "prettier"], | ||
"extends": ["plugin:@typescript-eslint/recommended", "prettier"], | ||
"env": { | ||
"node": true | ||
}, | ||
"ignorePatterns": ["dist", "libs"], | ||
"rules": { | ||
"no-console": 1, // Means warning | ||
"prettier/prettier": 2 // Means error | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# editor | ||
.vscode | ||
|
||
# node | ||
node_modules | ||
npm-debug.log | ||
|
||
# build | ||
dist | ||
|
||
# Otros | ||
.DS_Store | ||
coverage | ||
.nyc_output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
git-tag-version=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"trailingComma": "all", | ||
"singleQuote": true, | ||
"printWidth": 120, | ||
"semi": false, | ||
"tabWidth": 2, | ||
"useTabs": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Proceso de publicación | ||
|
||
```bash | ||
# Autenticación con npm | ||
npm login | ||
|
||
# Actualiza la versión (major | minor | patch) | ||
npm version patch | ||
|
||
# Publica el paquete en npm | ||
npm publish --access public | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2017 | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,109 @@ | ||
# express-response-handler | ||
<h1 align="center">Express Response Handler</h1> | ||
|
||
<p align="center"> | ||
<a href="https://github.com/ElArteDelCodigo/express-response-handler/releases"> | ||
<img src="https://img.shields.io/github/v/release/ElArteDelCodigo/express-response-handler" alt="release"> | ||
</a> | ||
<a href="https://github.com/ElArteDelCodigo/express-response-handler/blob/main/LICENSE"> | ||
<img src="https://img.shields.io/github/license/ElArteDelCodigo/express-response-handler" alt="License: MIT" /> | ||
</a> | ||
</p> | ||
|
||
Librería para gestionar las respuestas de un servicio web creado con express. | ||
|
||
## Instalación | ||
|
||
```bash | ||
npm install @elartedelcodigo/express-response-handler | ||
``` | ||
|
||
## Ejemplo | ||
|
||
```txt | ||
app | ||
└─ server.ts | ||
``` | ||
|
||
Archivo `server.ts` | ||
|
||
```ts | ||
import express, { Express, NextFunction, Request, Response } from 'express' | ||
import { ExpressLogger } from '@elartedelcodigo/express-logger' | ||
import { ResponseHandler, Result, PreconditionFailedError } from '@elartedelcodigo/express-response-handler' | ||
|
||
export class App { | ||
private app: Express | ||
|
||
constructor() { | ||
this.app = express() | ||
} | ||
|
||
initialize() { | ||
ExpressLogger.initialize(this.app) | ||
|
||
ResponseHandler.initialize(this.app, { | ||
logger: ExpressLogger.getInstance(), | ||
}) | ||
|
||
// eslint-disable-next-line | ||
this.app.get('/estado', (req: Request, res: Response, next: NextFunction) => { | ||
try { | ||
const result = { servicio: 'activo' } | ||
return Result.ok(res, result) | ||
} catch (err) { | ||
return Result.fail(res, err) | ||
} | ||
}) | ||
|
||
// eslint-disable-next-line | ||
this.app.get('/throw-error', (req: Request, res: Response, next: NextFunction) => { | ||
try { | ||
throw new PreconditionFailedError() | ||
} catch (err) { | ||
return Result.fail(res, err) | ||
} | ||
}) | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
this.app.use((err: Error, req: Request, res: Response, next: NextFunction) => { | ||
return Result.fail(res, err) | ||
}) | ||
} | ||
|
||
listen() { | ||
return this.app.listen(3000) | ||
} | ||
} | ||
``` | ||
|
||
Resultado 1: | ||
|
||
```bash | ||
curl --location 'http://localhost:3000/estado' | ||
``` | ||
|
||
```json | ||
{ | ||
"status": 200, | ||
"message": "Tarea completada exitosamente.", | ||
"data": { | ||
"servicio": "activo" | ||
} | ||
} | ||
``` | ||
|
||
Resultado 2: | ||
|
||
```bash | ||
curl --location 'http://localhost:3000/throw-error' | ||
``` | ||
|
||
```json | ||
{ | ||
"status": 412, | ||
"message": "No se cumple con alguna condición que es necesaria para completar la tarea.", | ||
"timestamp": 1682729565 | ||
} | ||
``` | ||
|
||
![Captura 1](./assets/screen_1.png) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.