// Listen for incoming requests. server.post('/api/messages', (req, res) => { adapter.processActivity(req, res, async (context) => { await bot.run(context); }); });
server.post('/product', function(req, res, next) { var product = req.params; db.products.save(product, function(err, data) { res.writeHead('200', { 'Content-Type': 'application/json; charset=utf-8' }); res.end(JSON.stringify(data)); }); return next(); });
// handling post updates app.post("/post_update", function (req, res, next) { var timestamp = req.body.start; var lastSync = req.body.lastSync; sendCumulativeMessages(timestamp, lastSync, res); return next(); });
tape('restify - handshake - failed', function(t) { t.plan(4); var server = restify.createServer() , fbbot = new Fbbot(common.fbbot) ; // plug-in fbbot server.get(common.server.endpoint, fbbot.requestHandler); server.post(common.server.endpoint, fbbot.requestHandler); // start the server server.listen(common.server.port, function() { common.sendHandshake('bad', function(error, response) { t.error(error, 'GET request should return no error'); t.equal(response.statusCode, 400, 'GET request should return code 400'); t.equal(response.body, common.handshakes['bad'].error, 'should received error message'); server.close(function() { t.ok(true, 'make sure server is closed'); }); }); }); });
/** * POST request router */ server.post( basepath, function ( req, res, next ) { res.setHeader( 'content-type', 'text/plain; charset=utf-8' ); if ( 'preview' in req.params ) { preview( req, res, next ); } if ( 'publish' in req.params ) { return publish( req, res, next ); } res.setHeader( 'content-type', 'text/plain' ); res.send( req.params ); } );
server.post(common.server.endpoint, fbbot.requestHandler);
// handling post messages app.post("/post_message", function (req, res, next) { var msg = { name: req.body.name, time: req.body.time, message: req.body.message, timestamp: (new Date()).getTime() }; req.logger.info("received message from %s", msg.name); if (redisRunning) { pub.publish("message", JSON.stringify(msg)); } else { pushLocal(msg); } res.send({}); return next(); });
server.post('/todos', (req, res, next) => { const todo = {}; const body = JSON.parse(req.body); todo.id = uuid.v4(); todo.text = body.text; console.log(`Received new todo: ${todo.text}`); MongoClient((db) =>{ db.collection('todos').insertOne(todo, (err) => { db.close(); if(err){ res.send(503, 'ERROR'); return next(); }else{ producer.publish(todo, (err, result) => { res.send(200); return next(); }); } }); }); });
/** * Render API */ server.post('/render', function (request, response, next) { // TODO: require() compiled webpack scripts // TODO: set window.location to url passed in as param // TODO: set view state from state passed in as param (figure out a better way than with globals) // TODO: render Root component as string // TODO: determine if route is valid and throw a 404 if not // TODO: response.send() rendered html response.send(501, {error: 'Not implemented'}); next(); });
server.post('/user/add', (req, res) => { console.log("req.body:", req.body) setTimeout(()=> res.send(200, {result: true}), 2000) })
// Listen for incoming requests. server.post('/api/messages', (req, res) => { adapter.processActivity(req, res, async (context) => { // Route theincoming activity to the main bot turn handler. await bot.onTurn(context); }); });
tape('restify - handshake - success', function(t) { t.plan(4); var server = restify.createServer() , fbbot = new Fbbot(common.fbbot) ; // plug-in fbbot server.get(common.server.endpoint, fbbot.requestHandler); server.post(common.server.endpoint, fbbot.requestHandler); // start the server server.listen(common.server.port, function() { common.sendHandshake('ok', function(error, response) { t.error(error, 'GET request should return no error'); t.equal(response.statusCode, 200, 'GET request should return code 200'); t.equal(response.body, common.handshakes['ok'].query['hub.challenge'], 'should receive provided challenge back'); server.close(function() { t.ok(true, 'make sure server is closed'); }); }); }); });
// Listen for incoming activities and route them to your bot main dialog. server.post('/api/messages', (req, res) => { adapter.processActivity(req, res, async (context) => { // route to main dialog. await bot.onTurn(context); }); });