Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
client.websocket.sendUTF(JSON.stringify({response: "alert", content: req.body.toString()})); // TESTED - WORKS A TREAT! - TODO check this works fine for XML too
// TODO do we want to send a multipart that describes the data???
}*/
logger.debug("RECEIVED ALERT!");
res.send("OK");
done();
self.close();
};
this.server = restify.createServer({name: "MLJSAlertServer"});
this.server.use(restify.bodyParser()); // { mapParams: false }
// Server request 1: handle echo directly to client
//server.get('/echo/:clientid', respond);
//server.head('/echo/:clientid', respond);
this.server.post('/alert/:clientid', respond);
var self = this;
this.server.listen(this.port, function() {
logger.debug((new Date()) + ' - MLJS Alert Receiving HTTP Server listening at %s', self.server.url);
});
logger.debug("Created alert server");
};
/* BOOKSHOP API */
var fs = require('fs')
var restify = require('restify')
var server = restify.createServer()
server.use(restify.fullResponse())
server.use(restify.queryParser())
server.use(restify.bodyParser())
server.use(restify.authorizationParser())
var accounts = require('./accounts.js')
var books = require('./books.js')
server.get('/library', function(req, res) {
console.log('GET /library')
const searchTerm = req.query.q
console.log('q='+searchTerm)
books.search(searchTerm, function(data) {
console.log(data)
res.setHeader('content-type', 'application/json');
res.send(data.code, data.response);
res.end();
})
})
const xmlbuilder = require('xmlbuilder');
// Setup Restify Server
const server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, () => {
console.log('%s listening to %s', server.name, server.url);
});
// Create chat bot and listen to messages
const connector = new builder.ChatConnector({
appId: process.env.MICROSOFT_APP_ID,
appPassword: process.env.MICROSOFT_APP_PASSWORD
});
server.post('/api/messages', connector.listen());
server.use(restify.bodyParser({ mapParams: false }));
server.get('/api/token', (req, res, next) => {
// make a request to get a token from the secret key
const jsonClient = restify.createStringClient({ url: 'https://directline.botframework.com/v3/directline/tokens/generate' });
jsonClient.post({
path: '',
headers: {
authorization: 'Bearer ' + process.env.DL_KEY
}
}, null, function (_err, _req, _res, _data) {
let jsonData = JSON.parse(_data);
console.log('%d -> %j', _res.statusCode, _res.headers);
console.log('%s', _data);
res.send(200, {
token: jsonData.token
});
next();
'use strict';
var Restify = require('restify');
var debug = require('debug')('flint-serve');
var _ = require('lodash');
// create / configure restify server
var restify = Restify.createServer({
'name': 'flint'
});
restify.use(Restify.bodyParser({
'mapParams': true,
'mapFiles': false,
'overrideParams': true
}));
restify.use(Restify.queryParser());
module.exports = {
listen: function(host, port) {
restify.listen(port, host, function() {
debug('is now listening on http://%s:%s',host, port);
});
},
route: function(method, resource, fn, cb) {
method = method.toLowerCase();
formatters: {
'application/json': function(req, res, body){
if(req.params.callback){
var callbackFunctionName = req.params.callback.replace(/[^A-Za-z0-9_\.]/g, '');
return callbackFunctionName + "(" + JSON.stringify(body) + ");";
} else {
return JSON.stringify(body);
}
},
'text/html': function(req, res, body){
return body;
}
}
});
mongodbServer.use(restify.bodyParser());
// Create a schema for our data
var MessageSchema = new Schema({
message: String,
date: Date
});
// Use the schema to register a model
mongoose.model('Message', MessageSchema);
var MessageMongooseModel = mongoose.model('Message'); // just to emphasize this isn't a Backbone Model
/*
this approach was recommended to remove the CORS restrictions instead of adding them to each request
but its not working right now?! Something is wrong with adding it to mongodbServer
const restify = require('restify')
const server = restify.createServer()
server.use(restify.bodyParser({ mapFiles: true }))
const gallery = require('./gallery')
server.post('/gallery', (req, res) => {
/* addPhoto takes the entire 'request' object as a parameter and returns an Error if something goes wrong. */
gallery.addPhoto(req, (err, data) => {
res.setHeader('content-type', 'application/json')
if (err) {
res.send(400, {status: 'error', message: err.message })
} else {
res.send(201, {status: 'success', message: 'photo uploaded', data: data})
}
})
})
server.get('/gallery', (req, res) => {
module.exports = function(root, apikey, notAuthorizedApiKey) {
var server = restify.createServer({
name: 'snyk-mock-server',
version: '1.0.0',
});
server.use(restify.acceptParser(server.acceptable));
server.use(restify.queryParser());
server.use(restify.bodyParser());
[root + '/verify/callback', root + '/verify/token'].map(function(url) {
server.post(url, function(req, res) {
if (req.params.api) {
if (
req.params.api === apikey ||
(notAuthorizedApiKey && req.params.api === notAuthorizedApiKey)
) {
return res.send({
ok: true,
api: apikey,
});
}
}
if (req.params.token) {
var now = Date.now();
res.header('Date', new Date());
res.header('x-request-id', req.getId());
var t = now - req.time();
res.header('x-response-time', t);
});
req.app = self;
req.backend = self.backend;
next();
});
admin.use(restify.requestLogger());
admin.use(restify.queryParser({mapParams: false}));
admin.use(restify.bodyParser());
admin.on('after', common.filteredAuditLog);
adminEndpoints.register(admin, self.log, [ common.checkServices ]);
};
function launch() {
var port = process.env.VCAP_APP_PORT || config.server.port || 8001,
server = restify.createServer({
name: "trissues",
version: "0.0.0",
formatters: {
"application/xml": function (req, res, body) {
return body;
}
}
});
server.use(restify.bodyParser());
server.get("/githubissues", handlers.githubissues);
server.post("/fromtracker", handlers.fromtracker);
server.post("/fromgithub", handlers.fromgithub);
server.listen(parseInt(port));
helpers.log("Server running at http://127.0.0.1:" + port + "/ (" + process.env.NODE_ENV + " mode)");
helpers.log("Config", config);
helpers.log("process env", process.env);
}
"use strict"
let restify = require('restify');
let TileService = require('./src/services/restify/TileService');
let DEFAULT_LAYER_TYPE = "associations";
let server = restify.createServer();
server.use(restify.bodyParser());
server.post('/TileFetcher', (req, res, next) => {
let layerType = req.params.layerType || DEFAULT_LAYER_TYPE;
if(req.params.bbox && req.params.zoomLevel && req.params.associations && req.params.keyword && req.params.period){
TileService.FetchTiles(req.params.bbox, req.params.zoomLevel, req.params.associations, req.params.keyword,
req.params.period, layerType, (error, response) => {
if(error){
let errorMsg = `Internal tile server error: [${JSON.stringify(error)}]`;
res.send(500, errorMsg);
}else{
res.send(201, response);
}
return next();