Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/* import the 'restify' module and create an instance. */
var restify = require('restify')
var server = restify.createServer()
/* import the required plugins to parse the body and auth header. */
server.use(restify.fullResponse())
server.use(restify.bodyParser())
server.use(restify.authorizationParser())
/* import our custom module. */
var lists = require('./lists.js')
/* if we receive a GET request for the base URL redirect to /lists */
server.get('/', function(req, res, next) {
res.redirect('/lists', next)
})
/* this route provides a URL for the 'lists' collection. It demonstrates how a single resource/collection can have multiple representations. */
server.get('/lists', function(req, res) {
console.log('getting a list of all the lists')
/* we will be including URLs to link to other routes so we need the name of the host. Notice also that we are using an 'immutable variable' (constant) to store the host string since the value won't change once assigned. The 'const' keyword is new to ECMA6 and is supported in NodeJS. */
const host = req.headers.host
console.log(host)
/* creating some empty variables */
constructor(restifyContactRouter) {
this.restifyContactRouter = restifyContactRouter;
console.log("RestifyApplication ctor");
// create restify server
this.restifyApplication = restify.createServer();
restify.CORS.ALLOW_HEADERS.push("authorization");
this.restifyApplication.use(restify.CORS());
this.restifyApplication.use(restify.pre.sanitizePath());
this.restifyApplication.use(restify.acceptParser(this.restifyApplication.acceptable));
this.restifyApplication.use(restify.bodyParser());
this.restifyApplication.use(restify.queryParser());
this.restifyApplication.use(restify.authorizationParser());
this.restifyApplication.use(restify.fullResponse());
// configure API and error routes
this.restifyContactRouter.configApiRoutes(this.restifyApplication);
this.restifyContactRouter.configErrorRoutes(this.restifyApplication);
}
bootstrap(port) {
module.exports = function (app, sessionKey) {
longjohn.async_trace_limit = 5; // defaults to 10
longjohn.empty_frame = 'ASYNC CALLBACK';
app.use(restify.acceptParser(app.acceptable));
app.use(restify.authorizationParser());
app.use(restify.dateParser());
app.use(restify.queryParser());
app.use(restify.jsonp());
app.use(restify.gzipResponse());
app.use(restify.bodyParser());
var os = require('os');
console.log(os.platform() + ", " + os.release());
// having issues on WIndows with nodegyp and toobusy, Windows SDK solution works on some platforms
// https://github.com/TooTallNate/node-gyp/#installation
if (os.platform().indexOf('win') < 0) {
console.log("Loading toobusy");
// send a 503 if the server is too busy
var toobusy = require('toobusy')
app.use(function(req, res, next) {
if (toobusy()) {
rest = restify.createServer({
name: "Scales",
certificate: fs.readFileSync(gconfig.ssl.cert),
key: fs.readFileSync(gconfig.ssl.key)
})
} else {
log.error(' ** WARNING: Missing HTTPS keys. **');
process.exit();
}
rest.use(restify.bodyParser());
rest.use(restify.authorizationParser());
rest.use(restify.queryParser());
rest.use(restify.CORS());
rest.opts(/.*/, function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Methods", req.header("Access-Control-Request-Method"));
res.header("Access-Control-Allow-Headers", req.header("Access-Control-Request-Headers"));
res.send(200);
return next();
});
// rest.on('uncaughtException', function (req, res, route, err) {
//
var connection = mysql.createConnection({
host : program.server,
user : config.mysql.user,
password : config.mysql.password,
database : config.mysql.database
});
connection.connect(function(err) {
if (err) throw err;
log('Connected to database');
});
var server = restify.createServer({name: 'R&D test'});
server.use(restify.acceptParser(server.acceptable));
server.use(restify.authorizationParser());
server.use(restify.dateParser());
server.use(restify.queryParser());
server.use(restify.bodyParser());
server.use(restify.throttle({
burst: 100,
rate: 50,
ip: true, // throttle based on source ip address
overrides: {
'127.0.0.1': {
//'192.168.0.12': {
rate: 0, // unlimited
burst: 0
}
}
}));
// Allow 5 requests/second by IP, and burst to 10
server.use(restify.throttle({
burst: 10,
rate: 5,
ip: true,
}));
// Use the common stuff you probably want
server.use(restify.acceptParser(server.acceptable));
server.use(restify.dateParser());
server.use(restify.queryParser());
server.use(restify.gzipResponse());
server.use(restify.bodyParser({
mapParams: true
})); // Allows for JSON mapping to REST
server.use(restify.authorizationParser()); // Looks for authorization headers
// Let's start using Passport.js
server.use(passport.initialize()); // Starts passport
server.use(passport.session()); // Provides session support
/**
/*
/* Calling the OIDCBearerStrategy and managing users
/*
/* Passport pattern provides the need to manage users and info tokens
/* with a FindorCreate() method that must be provided by the implementor.
/* Here we just autoregister any user and implement a FindById().
/* You'll want to do something smarter.
**/
/*
* NB: we're using [HAL](http://stateless.co/hal_specification.html) here to communicate RESTful links among our
* resources, but you could use any JSON linking format, or XML, or even just Link headers.
*/
var server = restify.createServer({
name: "Example Restify-OAuth2 Resource Owner Password Credentials Server",
version: require("./package.json").version,
formatters: {
"application/hal+json": function (req, res, body) {
return res.formatters["application/json"](req, res, body);
}
}
});
// Setup the Restify Server with Oauth2
server.use(restify.authorizationParser());
server.use(restify.bodyParser({ mapParams: false }));
restifyOAuth2.ropc(server, { tokenEndpoint: "/token", hooks: hooks });
require(routes_path + '/routes')(server, config);
var port = config.port;
server.listen(port);
module.exports = server;
'use strict';
var restify = require('restify');
var server = restify.createServer({
name: 'mock-server',
version: '1.0.0'
});
server.use(restify.acceptParser(server.acceptable));
server.use(restify.queryParser());
server.use(restify.bodyParser());
server.use(restify.authorizationParser());
server.use(restify.dateParser());
server.use(restify.CORS());
server.pre(restify.pre.sanitizePath());
server.pre(function (req, res, next) {
res.charSet('utf-8');
res.cache({maxAge: 0});
next();
});
require('./routes')(server);
server.listen(5050, function () {
console.log('Mock server listening at %s', server.url);
});
function initServer()
{
var filespath;
klServer = mod_restify.createServer({
'name': klName,
'log': klLog
});
klServer.on('uncaughtException', function (_1, _2, _3, err) {
klLog.fatal(err, 'uncaught exception from restify handler');
throw (err);
});
klServer.use(mod_restify.authorizationParser());
klServer.use(mod_restify.acceptParser(klServer.acceptable));
klServer.use(mod_restify.queryParser());
klServer.use(mod_restify.urlEncodedBodyParser());
filespath = mod_path.normalize(mod_path.join(__dirname, '..', 'docs'));
klServer.get('/', fileServer.bind(
null, mod_path.join(filespath, 'index.htm')));
klServer.get('/resources/.*', dirServer.bind(null, '/resources/',
mod_path.join(filespath, 'resources')));
klServer.post('/kart/video', auth, upload);
klServer.on('after', mod_restify.auditLogger({ 'log': klLog }));
klServer.listen(klPort, function () {
klLog.info('%s server listening at %s',
'use strict'
const rand = require('csprng')
const fs = require('fs')
const restify = require('restify')
const httpsOptions = {
key: fs.readFileSync('../key.pem'),
certificate: fs.readFileSync('../cert.pem')
}
const server = restify.createServer(httpsOptions)
server.use(restify.fullResponse())
server.use(restify.bodyParser())
server.use(restify.authorizationParser())
const status = {
'ok': 200,
'created': 201,
'notModified': 304,
'notFound': 404
}
const defaultPort = 8080
const lists = []
server.get('/', (req, res, next) => {
res.redirect('/lists', next)
})