https://github.com/midgarjs/express
https://github.com/midgarjs/express
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/midgarjs/express
- Owner: midgarjs
- License: mit
- Created: 2020-01-04T15:50:13.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-24T01:04:36.000Z (over 2 years ago)
- Last Synced: 2025-01-25T06:25:25.950Z (5 months ago)
- Language: JavaScript
- Size: 1.57 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://drone.midgar.io/Midgar/express)
[](https://sonar.midgar.io/dashboard?id=midgar-express)# @midgar/express
Ajoute un service expess [Express](https://expressjs.com/)
## Installation
```sh
$ npm i @midgar/express
```Si tout s'est bien passé, un message de confirmation s'affiche:
```sh
#midgar-cli
@midgar/express added to plugins.json !
```## Fonctionnement
Ajoute un service **mid:express**:
```js
const expressService = mid.getService('mid:express')// App express
const app = expressService.app
```## Ajouter un middlware express
```js
import morgan from 'morgan'
import { Plugin } from '@midgar/midgar'/**
* TestPlugin
*/
class TestPlugin extends Plugin {
init () {
// Listen @midgar/express:afterInit event
this.mid.on('@midgar/express:afterInit', (expressService) => {
expressService.app.use(morgan('combined'))
})
}
}export default TestPlugin
```## Configuration
Ceci est la configuration par défault si elle n'est pas modifié dans la configration de Midgar.
```js
{
...
express: {
port: 3000,
host: 'localhost',
ssl: false,
sslCert: '',
sslKey: ''
}
...
}```
Vous pouvez activer cors depuis cette même configuration:
```js
{
...
express: {
port: 3000,
...
cors: {
origin: 'https://domain.com',
credentials: true,
allowedHeaders: [
'Access-Control-Allow-Headers',
'Origin',
'Accept',
...
]
}
}
...
}```
Vous trouverez plus d'information sur la configuration du module cors [ici](https://www.npmjs.com/package/cors).