@noma/plugin-express

1.1.4 • Public • Published

@noma/plugin-express

Creates express.js applications and optionally binds to one or more HTTP and/or HTTPS servers' request event listeners.

Usage

main.js:

export default async function main({ express }) {
  express.app.get('/', (req, res) => {
    res.send('hello world')
  })
}

Configuring the default app

config/default.yml:

http:
  servers:
    other:
      port: 8080
express:
  apps:
    default:
      servers:
        - other

main.js:

export default async function main({ express }) {
  express.app.get('/', (req, res) => {
    res.send('hello world')
  })
}

Configuring multiple apps

config/default.yml:

https:
  servers:
    default:
      port: 8080
    app:
      port: 8081
    api:
      port: 8082
express:
  apps:
    default:
      servers:
        - default
        - app
        - api
    app:
      servers:
        - app
    api:
      servers:
        - api

main.js:

export default async function main({ express }) {
  express.apps.default.get('/', (req, res, next) => {
    res.set('X-Express-App-Name', 'default')

    next()
  })

  express.apps.app.get('/', (req, res, next) => {
    res.set('X-Express-App-Name', 'app')

    res.end()
  })

  express.apps.api.get('/', (req, res, next) => {
    res.set('X-Express-App-Name', 'api')

    res.end()
  })
}

Removing the default app

config/default.yml:

express:
  apps:
    default: null

License

Copyright 2021 Jonatan Pedersen

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.

Readme

Keywords

none

Package Sidebar

Install

npm i @noma/plugin-express

Weekly Downloads

15

Version

1.1.4

License

MIT

Unpacked Size

6.3 kB

Total Files

9

Last publish

Collaborators

  • oligrand
  • helderpractio
  • jonatanpedersen
  • gundlev