How to use the restify.pre function in restify

To help you get started, we’ve selected a few restify examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cmawhorter / hmmac / test / api / server.js View on Github external
var restify = require('restify');

var server = restify.createServer();
server.pre(restify.pre.pause());

// timeout requests
server.use(function(req, res, next) {
  next();

  res.timeoutFn = setTimeout(function() {
    if (!res.finished) res.end();
  }, 30000);
});

// we're done. clear timeout.
server.on('after', function(req, res, route, err) {
  if (res.timeoutFn) clearTimeout(res.timeoutFn);
});

server.use(restify.acceptParser(server.acceptable));
github science / openthermo / server / thermo-server.js View on Github external
var startServer = function (callBack) {
  // this line is a restify docs-provided hack to support curl as a client
  server.pre(restify.pre.userAgentConnection());
  server.get('/watchfile/:name', watchFileResponse);
  server.head('/watchfile/:name', watchFileResponse);
  server.get('/now/:name', getFileResponse)
  server.head('/now/:name', getFileResponse)

  server.listen(8080, function() {
    console.log('%s listening at %s', server.name, server.url);
    console.log('Current working directory is %s', process.cwd());
    if (typeof process.send == 'function'){process.send('started');};
    if (typeof callBack == 'function'){callBack();};
  });
  //Set the keep-alive timeout for all connections
  server.addListener("connection",function(stream) {
      stream.setTimeout(HTTP_KEEP_ALIVE_TIMEOUT_MSEC);
  });
}
github AzureAD / passport-azure-ad / examples / server-oauth2-b2c / server.js View on Github external
/**
 * Our Server
 */


var server = restify.createServer({
    name: "Windows Azure Active Directroy TODO Server",
    version: "2.0.1"
});

// Ensure we don't drop data on uploads
server.pre(restify.pre.pause());

// Clean up sloppy paths like //todo//////1//
server.pre(restify.pre.sanitizePath());

// Handles annoying user agents (curl)
server.pre(restify.pre.userAgentConnection());

// Set a per request bunyan logger (with requestid filled in)
server.use(restify.requestLogger());

// 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));
github vmadman / win-dns-api / lib / server.js View on Github external
// Include Restify REST framework
// http://mcavage.me/node-restify/
var restify = require('restify');

// Child process module
var exec = require('child_process').exec;

// Create the server object
var server = restify.createServer({
	name: 'WinDnsApi'
});

// Special logic for CURL's keep-alive behavior
server.pre(restify.pre.userAgentConnection());

// DNS Record Creates/Updates
function doDnsSet(req, res, next) {

	var RRType = req.params.type.toUpperCase(),
		ZoneName = req.params.zone,
		NodeName = req.params.node,
		IpAddress = req.params.ip;

	// Validate RRType
	if( RRType != "A" ) {
		return next(new restify.InvalidArgumentError("You specified an invalid record type ('" + RRType + "'). Currently, only the 'A' (alias) record type is supported.  e.g. /dns/my.zone/A/.."));
	}

	// Validate Zone Name
	if( ZoneName.match(/[^A-Za-z0-9\.-]+/g) !== null ) {
github joyent / sdc-adminui / lib / adminui.js View on Github external
log.warn('Using default self-signed certificate');
        var pem = fs.readFileSync(DEFAULT_SSL_CERT, 'ascii');
        cert = pem;
        key = pem;
    }

    var server = restify.createServer({
        name: 'adminui',
        log: log,
        certificate: cert,
        key: key
    });

    server.root = this.root;
    server.pre(restify.pre.pause());
    server.pre(restify.pre.sanitizePath());
    server.use(restify.requestLogger());
    server.use(restify.queryParser());
    server.use(restify.gzipResponse());
    server.use(restify.acceptParser(server.acceptable));
    server.use(paramsTrimmer);

    TraceEvent.mount({
        skipRoutes: ['ping', 'getca'],
        server: server
    });

    if (config.simulateLatency) {
        server.use(require('./fake-latency').simulateLatency());
    }

    // Mounts the SDC clients to req.sdc
github tes / seguir / server / index.js View on Github external
directory: './doc',
    default: 'index.html'
  }));

  server.get('/status', function (req, res, cb) {
    api.auth.getAccounts(function (err, accounts) {
      if (err) { return _error(err); }
      var statusConfig = _.clone(config);
      delete statusConfig.logger;
      res.send({status: 'OK', config: statusConfig, accounts: accounts});
      cb();
    });
  });

  // Preflight
  server.pre(restify.pre.sanitizePath());
  server.pre(restify.pre.userAgentConnection());

  server.get('/', api.auth.checkRequest, function (req, res, cb) {
    res.send({status: 'Seguir - OK'});
    cb();
  });

  var coerce = api.auth.coerceUserToUuid;

  function _error (err) {
    return new restify.HttpError(err);
  }

  function _response (res, next) {
    return function (err, result) {
      if (err) { return next(_error(err)); }
github AzureADQuickStarts / AppModelv2-WebAPI-nodejs / node-server / app.js View on Github external
* Our Server
 */

var server = restify.createServer({
    name: "Windows Azure Active Directroy TODO Server",
    version: "2.0.1"
});

// Ensure we don't drop data on uploads
server.pre(restify.pre.pause());

// Clean up sloppy paths like //todo//////1//
server.pre(restify.pre.sanitizePath());

// Handles annoying user agents (curl)
server.pre(restify.pre.userAgentConnection());

// Set a per request bunyan logger (with requestid filled in)
server.use(restify.requestLogger());

// 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());
github AzureADQuickStarts / AppModelv2-WebAPI-nodejs / node-server / app.js View on Github external
this.name = 'MissingTaskError';
}
util.inherits(MissingTaskError, restify.RestError);

/**
 * Our Server
 */

var server = restify.createServer({
    name: "Windows Azure Active Directroy TODO Server",
    version: "2.0.1"
});

// Ensure we don't drop data on uploads
server.pre(restify.pre.pause());

// Clean up sloppy paths like //todo//////1//
server.pre(restify.pre.sanitizePath());

// Handles annoying user agents (curl)
server.pre(restify.pre.userAgentConnection());

// Set a per request bunyan logger (with requestid filled in)
server.use(restify.requestLogger());

// Allow 5 requests/second by IP, and burst to 10
server.use(restify.throttle({
    burst: 10,
    rate: 5,
    ip: true,
}));
github tes / seguir / server.js View on Github external
var restify = require('restify');
var api = require('./index');

var server = restify.createServer();

server.use(restify.bodyParser({
    mapParams: true
}));
server.use(restify.gzipResponse());
server.pre(restify.pre.userAgentConnection());

/**
 * @apiDefine Users Users
 * This is a collection of methods that allow you to create and retrieve users.
 */

/**
 * @api {post} /user Add a user
 * @apiName AddUser
 * @apiGroup Users
 * @apiVersion 1.0.0
 *
 * @apiDescription Creates a new user.
 * @apiParam {String} username the name of the user
 *
 * @apiExample {curl} Example usage:
github kayslay / hotels / app.js View on Github external
const restify = require('restify');

const route = require("./routes");


const server = restify.createServer();


server.pre(restify.pre.sanitizePath());
server.use(restify.plugins.bodyParser());
server.use(restify.plugins.queryParser());
server.use(restify.plugins.gzipResponse());
route(server)

module.exports = server;