Support for mounting diet as middleware layer.
frank-dspeed opened this issue · 5 comments
This will Add cross compatiblity to diet.js
Allow: use in express diet.js middelware.
Allow: use httpCreate server with diet.js
Allow: use of express middelware in dietjs without converting via converting signal to req, res and vice versa with perserving Options!
build and return a function called diet.mount(req, res, next)
This will allow mounting dietjs as a middleware routing layer of express, connect, httpServer
We will offer a extra mount point that can be used in express, connect, httpServer.create()
that takes req, res, next only forms signal
this will allow:
app = require('express')
diet = require('diet')
diet.get('/', function($){
console.log('1st route', '1st middleware')
$.end('hello world!', true); // <-- stop middleware chain
}, function(){
console.log('1st route', '2nd middleware')
})
diet.get('/', function(){
console.log('2nd route', '1st middleware')
})
// diet.mount convert req, res, next to signal that used req, res, next
app.use(diet.mount(options))
+1
Update we can make a transformation handler:
we need to make the signal forming method aviable via app.createSignal(req, res) so we can do
var expapp = require('express')()
function giveExpress($) {
// $.return is optional if it is in next() inside express app will init next route of dietjs
/* if you leave it empty express will form a new empty next object and use that to process its middelware good for bigger express apps but the app needs a attached take express method to jump backk to diet.js if needed or it can directly respond
*/
expapp($.reqest, $.response, $.return)
}
send from express app to diet app
function takeExpress(req, res, next) {
$ = app.createSignal(req, res)
// Create Signal should maybe merge res.locals to $.data as optional option merge!
$.return()
}
maybe #43 will solve this too via registering and listing on express:// protocol and then return the http server object of a express app needs reviewing if this is possible
+1
@askie https://www.npmjs.com/package/diet-express
if your interrested in this