Generador de proyecto microservicio para ColComercio
Este generador -basado en el desarrollo de Carmine DiMascio (https://www.npmjs.com/package/generator-express-no-stress)- permite crear una base de desarrollo para los proyectos microservicio en ColComercio.
El proyecto generado adopta las siguientes funcionalidades:
- Express.js - framework de publicación HTTP para Node.js
- Swagger - Permite que la validación de la mensajería JSON automaticamente se compruebe contra la definición de contrato OpenAPI (Swagger) obligatorio para los API que se construyan en ColComercio
- SwaggerUI - Publica la documentación swagger hacia usuario del microservicios
- Babel.js - Permite utilizar una sintaxis moderna de JS
- Pino - Plataforma de logs que se acoplará a las capacidades de LOG de OpenShift
- dotenv - Carga los valores de parametrización por ambiente del archivo .env:
- ESLint - Ayuda a mejora el estilo de escritura de JS utilizando las definiciones basadas por AirBnB Airbnb
- Prettier - Prettier is an opinionated code formatter
El proyecto generado facilita las siguientes capacidades en tiempo de desarrollo:
- nodemon - Permite que el desarrollador
- [mocha]
generator-colco-microservice gets you up and running in seconds. It's ridiculously easy to configure. Heck, just take the defaults. Start it. Write code.
This generator scaffolds a fully functioning REST API server, complete with interactive documentation, API validation, structured logging, environment driven config, and more. Simply run the generator and smile :-D
Requires Node 8 or greater
npm install -g yo generator-colco-microserviceyo colco-microservice myapp
cd myappRun in development mode:
npm run devPackage and run in production mode
npm run compile
npm startnpm testRun one of the following, then attach your favorite inspector e.g. VSCode:
# debug the server
npm run dev:debug
# debug the tests
npm run test:debug- Interactive API doc at http://localhost:3000/api-explorer
- Landing page at http://localhost:3000
yo colco-microservice [appname] [--yarn] [--docker]| Option | default | Description |
|---|---|---|
appname |
myapp | The application folder |
--yarn |
- | Use the yarn package manager, instead of npm |
--docker |
Install Docker artifacts including a Dockerfile |
The sections below describe all usage options available once the project is generated/scaffolded.
| Target | Description |
|---|---|
npm run dev |
Run in development mode |
npm run dev:debug |
Debug in development mode |
npm run test |
Run tests |
npm run test:debug |
Deubg tests |
npm run lint |
View a listing of all errors discovered by the linter |
npm run lint:fix |
Fix all errors discovered by the linter |
npm run compile |
Transpile source code for production use |
npm start |
Run the in production mode. *Requires running npm run compile first |
Add these contents to your .vscode/launch.json file
Despliegue a entorno Desarrollo
oc ???? push myapp
La validación se realiza de forma automática contra las definiciones del Swagger 2.0:
- Interactive documentation
- API validation
????
Structured logging out of the box!
Structured logging pretty printed by default - great for dev!
Simply describe your APIs with Swagger and automatically get:
- API request validation
- Interactive documentation
swagger: '2.0'
info:
version: 1.0.0
title: myapp
description: My cool app
basePath: /api/v1
tags:
- name: Examples
description: Simple example endpoints
- name: Specification
description: The swagger API specification
consumes:
- application/json
produces:
- application/json
definitions:
ExampleBody:
type: object
title: example
required:
- name
properties:
name:
type: string
example: no_stress
paths:
/examples:
get:
tags:
- Examples
description: Fetch all examples
responses:
200:
description: Returns all examples
post:
tags:
- Examples
description: Create a new example
parameters:
- name: example
in: body
description: an example
required: true
schema:
$ref: "#/definitions/ExampleBody"
responses:
200:
description: Returns all examples
/examples/{id}:
get:
tags:
- Examples
parameters:
- name: id
in: path
required: true
description: The id of the example to retrieve
type: integer
responses:
200:
description: Return the example with the specified id
404:
description: Example not found
/spec:
get:
tags:
- Specification
responses:
200:
description: Return the API specificationcolco-microservice uses ESLint and provides two choices, Airbnb or Prettier.
To add your own ESLint customizations, edit.eslintrc.json.
Note that the Airbnb variant provides a slightly modified Airbnb base configuration.
Q: What about Node.js 6.x?
A:generator-colco-microservice now uses Babel 7. Babel 7 tooling requires Node.js 8 or greater. To use generator-colco-microservice with Node.js 6, install version 3.5.4.
npm install -g yo [email protected]