Created
September 4, 2015 23:59
-
-
Save tjanczuk/83599f34b04505da0461 to your computer and use it in GitHub Desktop.
Express test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Boom = require('boom'); | |
var Bluebird = require('bluebird'); | |
var Express = require('express'); | |
var Webtask = require('webtask-tools'); | |
var app = Express(); | |
var router = Express.Router(); | |
// do some async stuff | |
app.use(function (req, res, next) { | |
console.log('BEFORE JSON'); | |
setTimeout(next, 1000); | |
}); | |
// Parse incoming json bodies | |
app.use(require('body-parser').json()); | |
app.use(function (req, res, next) { | |
console.log('AFTER JSON'); | |
next(); | |
}); | |
app.use(router); | |
app.use(function(err, req, res, next) { | |
console.log(err.message); | |
console.log(err.stack); | |
if (!err.isBoom) err = Boom.wrap(err); | |
res | |
.set(err.output.headers) | |
.status(err.output.statusCode) | |
.json(err.output.payload); | |
}); | |
router.post('/reserve', function (req, res, next) { | |
console.log('IN /reserve', req.body); | |
res.json({ok:1}); | |
}); | |
module.exports = Webtask.fromConnect(app); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment