// for markdown preview app.post('/markdown', (request, reply) => { const { comment } = request.body; reply.send({ html: marked(comment.trim()) }); });
/* * Post new meta data for metrics. */ api.post('/metrics/v2/:id', handler((req, res) => { return Promise.map(plugins, plugin => { const reporter = new plugin.Reporter(config[plugin.config]); return reporter.ping() .then(() => reporter.report(_.merge({}, req.body, {instance: req.params.id}))) .then(() => log.info('Reported to %s', plugin.name)) .then(() => reporter.close()); }); }));
// settings app.post('/setting/:property/:value', (request, reply) => { const { property, value } = request.params; const user = getUser(request); if (!isAdmin(user)) return reply.status(403).send(request.params); const setting = value ? 1 : 0; db.run(queries.set_settings, [property, setting], err => { if (error(err, request, reply)) return; reply.send({ status: 'ok' }); }); });
api.post('/hook', function (req, res) { var signature = req.get('X-PDF-Signature', 'sha1=') var bodyCrypted = require('crypto') .createHmac('sha1', '12345') .update(JSON.stringify(req.body)) .digest('hex') if (bodyCrypted !== signature) { res.status(401).send() return } console.log('PDF webhook received', JSON.stringify(req.body)) res.status(204).send() })
function startServer(done) { const app = express(); app.use(bodyParser.json({ type: '*/*' })); app.get('/hello', function(req, res) { res.json({ response: 'OK' }); }); app.get('/404', function(req, res) { res.status(404); res.send('NO'); }); app.get('/301', function(req, res) { res.status(301); res.location('/hello'); res.send(); }); app.post('/echo', function(req, res) { res.json(req.body); }); app.get('/qs', function(req, res) { res.json(req.query); }); return app.listen(13371, undefined, done); }
// trust/block users or approve/reject comments app.post( /\/(?:comment\/(\d+)\/(approve|reject))|(?:user\/(\d+)\/(trust|block))/, (request, reply) => { const user = getUser(request); if (!isAdmin(user)) return reply.status(403).send(request.params); const action = request.params[1] || request.params[3]; const target_id = +(request.params[0] || request.params[2]); db.run(queries[action], target_id, err => { if (error(err, request, reply)) return; reply.send({ status: 'ok' }); }); } );
api.post('/', function(req, res) { var queue = createQueue() var authHeader = req.get('Authorization')
// POST new comment app.post('/comments/:slug', (request, reply) => { const { slug } = request.params; const { comment, replyTo } = request.body; const user = getUser(request); if (!user) return error('access denied', request, reply, 403); checkValidComment(db, slug, user.id, comment, replyTo, err => { if (err) return reply.send({ status: 'rejected', reason: err }); let stmt = db .prepare(queries.insert, [user.id, slug, comment, replyTo ? +replyTo : null]) .run(err => { if (err) return error(err, request, reply); if (!user.blocked && !user.trusted) { awaiting_moderation.push({ slug }); } schnackEvents.emit('new-comment', { user: user, slug, id: stmt.lastID, comment, replyTo }); reply.send({ status: 'ok', id: stmt.lastID }); }); }); });
app.post('/', async (req, res, next) => { const {team} = req.body; const timestamp = new Date();
this.app.post('/miner/mine', (req, res, next) => { miner.mine(req.body.rewardAddress, req.body['feeAddress'] || req.body.rewardAddress) .then((newBlock) => { newBlock = Block.fromJson(newBlock); blockchain.addBlock(newBlock); res.status(201).send(newBlock); }) .catch((ex) => { if (ex instanceof BlockAssertionError && ex.message.includes('Invalid index')) next(new HTTPError(409, 'A new block were added before we were able to mine one'), null, ex); else next(ex); }); });
this.app.post('/blockchain/transactions', (req, res) => { let requestTransaction = Transaction.fromJson(req.body); let transactionFound = blockchain.getTransactionById(requestTransaction.id); if (transactionFound != null) throw new HTTPError(409, `Transaction '${requestTransaction.id}' already exists`); try { let newTransaction = blockchain.addTransaction(requestTransaction); res.status(201).send(newTransaction); } catch (ex) { if (ex instanceof TransactionAssertionError) throw new HTTPError(400, ex.message, requestTransaction, ex); else throw ex; } });
app.post('/sms', (req, res) => { console.log('POST sms received'); try { bot.processMessage(req, res); } catch (err) { return res.status(400).send('Error while processing ' + err.message); } });
this.app.post('/operator/wallets', (req, res) => { let password = req.body.password; if (R.match(/\w+/g, password).length <= 4) throw new HTTPError(400, 'Password must contain more than 4 words'); let newWallet = operator.createWalletFromPassword(password); let projectedWallet = projectWallet(newWallet); res.status(201).send(projectedWallet); });
/* * Post new meta data for metrics. */ api.post('/metrics/v2/:id', handler((req, res) => { return Promise.map(plugins, plugin => { const reporter = new plugin.Reporter(config[plugin.config]); return reporter.ping() .then(() => reporter.report(_.merge({}, req.body, {instance: req.params.id}))) .then(() => log.info('Reported to %s', plugin.name)) .then(() => reporter.close()); }); }));
app.post('/webhook', (req, res) => { console.log('POST webhook'); try { bot.processMessage(req, res); } catch (err) { return res.status(400).send('Error while processing ' + err.message); } });