A stand-alone version of Expressive.js for Express middleware. [Create express routes from an object!]
You may be looking for Express plugin for Expressive.js
npm install https://github.com/bugs181/expressive-middleware/ --save
const expressive = require('expressive-middleware')
const app = require('express')()
app.use(expressive(routes))
app.listen(80)
const routes = {
user: function(name, callback) {
callback(null, `Username: ${name}`)
},
}
const routes = {
users: {
create: function(user, password, callback) {
},
read: function(user, callback) {
callback(null, 'OKAY')
},
...
},
}
const terms = {
verbs: {
create: 'post',
read: 'get',
update: 'put',
delete: 'delete',
list: 'options',
}
}
const routes = {
users: {
post: createUser, // Function
get: getUser, // Function
...
}
}
...
app.use(expressive(routes, terms))
const config = {
statusInResponse: true, // If data is JSON, sends status code along with data.
routeNotFound: '404', // Can be a 404.html file. fs.fileSync('404.html')
}
...
app.use(expressive(routes, config))
The full routing capabilities of Expressive can be found here:
Expressive Documentation