var express = require('express'); var app = express(); app.set('json spaces', 0); app.use(function (req, res, next){ if ('/echo' != _AN_Read_url('url', req)) return next(); res.set(req.headers); req.pipe(res); } ); app.use(express.bodyParser()); app.use(express.cookieParser()); app.use(function (req, res, next){ res.cookie('name', 'tobi'); next(); } ); app.use('/xdomain', function (req, res, next){ if (!req.get('Origin')) return next(); res.set('Access-Control-Allow-Origin', req.get('Origin')); res.set('Access-Control-Allow-Credentials', 'true'); res.set('Access-Control-Allow-Methods', 'POST'); res.set('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type'); if ('OPTIONS' == req.method) return _AN_Call_send('send', res, 200); next(); } ); app.get('/', function (req, res){ res.redirect('/test/'); } ); app.get('/error', function (req, res){ _AN_Call_send('send', res.status(500), 'fail'); } ); app.get('/unauthorized', function (req, res){ _AN_Call_send('send', res, 401); } ); app.get('/bad-request', function (req, res){ _AN_Call_send('send', res, 400); } ); app.get('/not-acceptable', function (req, res){ _AN_Call_send('send', res, 406); } ); app.get('/no-content', function (req, res){ _AN_Call_send('send', res, 204); } ); app.get('/delay/:ms', function (req, res){ var ms = ~~req.params.ms; _AN_Call_settimeout('setTimeout', window, function (){ _AN_Call_send('send', res, 200); } , ms); } ); app.put('/user/:id', function (req, res){ _AN_Call_send('send', res, 'updated'); } ); app.patch('/user/:id', function (req, res){ _AN_Call_send('send', res, 'updated'); } ); app.get('/querystring', function (req, res){ _AN_Call_send('send', res, req.query); } ); app.post('/todo/item', function (req, res){ var buf = ''; req.on('data', function (chunk){ buf += chunk; } ); req.on('end', function (){ _AN_Call_send('send', res, 'added "' + buf + '"'); } ); } ); app.post('/user/:id/pet', function (req, res){ _AN_Call_send('send', res, 'added pet "' + req.body.pet + '"'); } ); app.post('/user', function (req, res){ _AN_Call_send('send', res, 'created'); } ); app.del('/user/:id', function (req, res){ _AN_Call_send('send', res, 'deleted'); } ); app.all('/echo-header/:field', function (req, res){ _AN_Call_send('send', res, req.headers[req.params.field]); } ); app.post('/pet', function (req, res){ _AN_Call_send('send', res, 'added ' + req.body.name + ' the ' + req.body.species); } ); app.get('/pets', function (req, res){ _AN_Call_send('send', res, ['tobi', 'loki', 'jane'] ); } ); app.get('/text', function (req, res){ _AN_Call_send('send', res, "just some text"); } ); app.get('/foo', function (req, res){ _AN_Call_send('send', res.header('Content-Type', 'application/x-www-form-urlencoded'), 'foo=bar'); } ); app.post('/auth', function (req, res){ var auth = req.headers.authorization, parts = auth.split(' '), credentials = new Buffer(parts[1], 'base64').toString().split(':'), user = credentials[0], pass = credentials[1]; _AN_Call_send('send', res, { user: user, pass: pass} ); } ); app.get('/xdomain', function (req, res){ _AN_Call_send('send', res, req.cookies.name); } ); app.use(express["static"] (__dirname + '/../')); var server = app.listen(process.env.ZUUL_PORT, function (){ } );