1.0.7 • Published 5 years ago

easy-router-express v1.0.7

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

easy-router-express

easy-router-express is writed for building a easy router for express

Support

  • Express

Installation

npm install easy-router-express
# or yarn
yarn add easy-router-express

Getting started

Use in Express

EasyRouter(app, router, options, ...params)

app

const app = new require('express')()

router

const router = new require('express').Router()

options

AttributeDescriptionTypeDefault
PathRouter Folder 's PathString`${__dirname}/router`
PrefixRouter 's PrefixStringNull
ProxyRouter 's ProxyObject/ArrayNull

Proxy

AttributeTypeExample
methodString'POST'
FuncFunction(req, res, next) => { next() }

Example

server.js

const Express = require('express')
const EasyRouter = require('easy-router-express')
const app = new Express()
const router = new Express.Router()
const path = __dirname + '/router'

EasyRouter(app, router, {
  path,
  prefix: '/api',
  proxy: {
    method: 'POST',
    func (req, res, next) {
      next()
    }
  }
})

app.listen(3000, () => {
  console.log('please visit http://localhost:3000')
})

router/demo.js

module.exports = (router) => {
  router.get('/test', (req, res) => {
    console.log('this is a demo')
    res.status(200).send('OK')
  })
}
1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago