Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const express = require('express')
const bodyParser = require('body-parser')
const cote = require('cote')
const axios = require('axios')
const app = express()
app.use(bodyParser.json())
const restaurantsRequester = new cote.Requester({ name: 'restaurants requester', key: 'restaurants' })
const orderRequester = new cote.Requester({ name: 'order requester', key: 'orders' })
const deliveryRequester = new cote.Requester({ name: 'delivery requester', key: 'deliveries' })
app.get('/restaurants', async (req, res) => {
const restaurants = await restaurantsRequester.send({ type: 'list' })
res.send(restaurants);
})
app.post('/order', async (req, res) => {
const order = await orderRequester.send({ type: 'create order', order: req.body })
const delivery = await deliveryRequester.send({ type: 'create delivery', order })
res.send({ order, delivery })
})
app.listen(3000, () => console.log('listening'))
var cote = require('cote'),
models = require('../models');
var purchaseResponder = new cote.Responder({
name: 'purchase responder',
namespace: 'purchase',
respondsTo: ['buy']
});
var purchasePublisher = new cote.Publisher({
name: 'purchase publisher',
namespace: 'purchase',
broadcasts: ['update']
});
var paymentRequester = new cote.Requester({
name: 'payment requester',
key: 'payment'
});
purchaseResponder.on('*', console.log);
purchaseResponder.on('buy', function(req, cb) {
var purchase = new models.Purchase({});
models.Product.get(req.productId, function(err, product) {
if (product.stock == 0) return cb(true);
paymentRequester.send({ type: 'process', userId: req.userId, price: product.price }, function(err) {
if (err) return cb(err);
product.stock--;
var express = require('express');
var cote = require('cote');
var app = express();
var timeRequester = new cote.Requester({
name: 'Time Requester'
});
app.get('/', function(req, res) {
res.send('Hello World!');
});
app.get('/time', function(req, res) {
timeRequester.send({type: 'time'}, function(time) {
res.send(time);
});
});
app.listen(3000, function() {
console.log('API server listening on port 3000!');
});
const express = require('express')
const bodyParser = require('body-parser')
const cote = require('cote')
const axios = require('axios')
const app = express()
app.use(bodyParser.json())
const restaurantsRequester = new cote.Requester({ name: 'restaurants requester', key: 'restaurants' })
const orderRequester = new cote.Requester({ name: 'order requester', key: 'orders' })
const deliveryRequester = new cote.Requester({ name: 'delivery requester', key: 'deliveries' })
app.get('/restaurants', async (req, res) => {
const restaurants = await restaurantsRequester.send({ type: 'list' })
res.send(restaurants);
})
app.post('/order', async (req, res) => {
const order = await orderRequester.send({ type: 'create order', order: req.body })
const delivery = await deliveryRequester.send({ type: 'create delivery', order })
res.send({ order, delivery })
})
app.listen(3000, () => console.log('listening'))
(function () {
const cote = require('cote');
cote_resp = new cote.Responder({ name: 'bench-remote' });
cote_req = new cote.Requester({ name: 'bench-remote' });
cote_resp.on('add', (req, cb) => {
cb(req.a + req.b);
});
bench.add("Cote", done => {
cote_req.send({ type: 'add', a: 5, b: 3 }, res => done());
});
})();
purchaseRequester.send({type: 'list'}, function(err, purchases) {
res.send(purchases);
});
});
var productRequester = new cote.Requester({
name: 'admin product requester',
namespace: 'product'
});
var userRequester = new cote.Requester({
name: 'admin user requester',
namespace: 'user'
});
var purchaseRequester = new cote.Requester({
name: 'admin purchase requester',
namespace: 'purchase'
});
server.listen(5000);
new cote.Sockend(io, {
name: 'admin sockend server'
});
const express = require('express')
const bodyParser = require('body-parser')
const cote = require('cote')
const axios = require('axios')
const app = express()
app.use(bodyParser.json())
const restaurantsRequester = new cote.Requester({ name: 'restaurants requester', key: 'restaurants' })
const orderRequester = new cote.Requester({ name: 'order requester', key: 'orders' })
const deliveryRequester = new cote.Requester({ name: 'delivery requester', key: 'deliveries' })
app.get('/restaurants', async (req, res) => {
const restaurants = await restaurantsRequester.send({ type: 'list' })
res.send(restaurants);
})
app.post('/order', async (req, res) => {
const order = await orderRequester.send({ type: 'create order', order: req.body })
const delivery = await deliveryRequester.send({ type: 'create delivery', order })
res.send({ order, delivery })
})
res.send(users);
});
});
app.get('/purchase', function(req, res) {
purchaseRequester.send({type: 'list'}, function(err, purchases) {
res.send(purchases);
});
});
var productRequester = new cote.Requester({
name: 'admin product requester',
namespace: 'product'
});
var userRequester = new cote.Requester({
name: 'admin user requester',
namespace: 'user'
});
var purchaseRequester = new cote.Requester({
name: 'admin purchase requester',
namespace: 'purchase'
});
server.listen(5000);
new cote.Sockend(io, {
name: 'admin sockend server'
});
});
});
app.get('/user', function(req, res) {
userRequester.send({type: 'list'}, function(err, users) {
res.send(users);
});
});
app.get('/purchase', function(req, res) {
purchaseRequester.send({type: 'list'}, function(err, purchases) {
res.send(purchases);
});
});
var productRequester = new cote.Requester({
name: 'admin product requester',
namespace: 'product'
});
var userRequester = new cote.Requester({
name: 'admin user requester',
namespace: 'user'
});
var purchaseRequester = new cote.Requester({
name: 'admin purchase requester',
namespace: 'purchase'
});
server.listen(5000);