How to use the restify.gzipResponse 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 kwhitley / apicache / test / api / restify-gzip.js View on Github external
function MockAPI(expiration, options, toggle) {
  var apicache = require('../../src/apicache').newInstance(options)
  var app = restify.createServer()

  // ENABLE COMPRESSION
  var whichGzip = restify.gzipResponse && restify.gzipResponse() || restify.plugins.gzipResponse()
  app.use(whichGzip)

  // EMBED UPSTREAM RESPONSE PARAM
  app.use(function(req, res, next) {
    res.id = 123
    next()
  })

  // ENABLE APICACHE
  app.use(apicache.middleware(expiration, toggle))
  app.apicache = apicache

  app.use(function(req, res, next) {
    res.charSet('utf-8')
    next()
  })
github joyent / sdc-adminui / lib / adminui.js View on Github external
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
    config.log = log;
    var sdcClients = require('./sdc-clients').createClients(config);
    var self = this;
github AzureAD / passport-azure-ad / examples / server-oauth2 / server.js View on Github external
// 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());
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.
github AzureAD / passport-azure-ad / examples / server-oauth2-b2c / server.js View on Github external
// 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());
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.
github tes / seguir / server / index.js View on Github external
function bootstrapServer (api, config, next) {

  var server = restify.createServer({
    name: 'seguir',
    version: '0.1.0',
    log: config.logger || defaultLogger
  });

  // Default middleware
  server.use(restify.bodyParser({mapParams: true}));
  server.use(restify.queryParser({mapParams: false}));
  server.use(restify.gzipResponse());
  server.use(restify.CORS());
  server.use(function (req, res, cb) {
    debug(req.url, req.params, req.headers);
    cb();
  });

  // Logging
  server.on('after', function (request, response, route, error) {
    var fn = error ? 'error' : 'info';
    if (api.config.logging) {
      request.log[fn]({req: request, res: response, route: route, err: error}, 'request');
    }
  });

  server.get(/\/docs\/current\/?.*/, restify.serveStatic({
    directory: './doc',
github flowgrammable / flowsim / backend / src / server / index.js View on Github external
secure_port: defSecurePort
  };

  this.logger = logger.addLog(name);

  // Set default values in case where passed config is deficient
  this.config.address     = this.config.address     || defAddress;
  this.config.hostname    = this.config.hostname    || defHostname;
  this.config.open_port   = this.config.open_port   || defOpenPort;
  this.config.secure_port = this.config.secure_port || defSecurePort;
  this.config.protocol    = this.config.production ? 'https' : 'http';

  // Create and configure a server instance
  this.server = restify.createServer()
    .use(restify.jsonp())
    .use(restify.gzipResponse())
    .use(restify.bodyParser());

  this.running = false;
}
exports.Server = Server;
github danhawkes / react-update-server / src / Server.js View on Github external
constructor(dataDir) {

    let config = require(path.join(dataDir, 'config'));

    let resolver = new Resolver(config);

    let server = restify.createServer();
    server.name = 'react-update-server';
    server.use(restify.queryParser());
    server.use(restify.gzipResponse());

    server.get('/update-check', (req, res, next) => {

      let {id, platform, container, bundle} = req.query;

      if (id === undefined) {
        res.send(400, new Error(`'id' parameter is missing.`));
      }
      if (platform === undefined) {
        res.send(400, new Error(`'platform' parameter is missing.`));
      }
      if (container === undefined) {
        res.send(400, new Error(`'container' version parameter is missing.`));
        return next();
      }
      if (!semver.valid(container)) {
github jwerle / pineapple / lib / server / adapters / restify.js View on Github external
create : function() {
    var server = restify.createServer.apply(restify, arguments);

    server.use(restify.acceptParser(server.acceptable));
    server.use(restify.authorizationParser());
    server.use(restify.dateParser());
    server.use(restify.queryParser());
    server.use(restify.jsonp());
    server.use(restify.gzipResponse());
    server.use(restify.bodyParser());
    server.use(restify.throttle({
      burst     : 100,
      rate      : 50,
      ip        : true,
      overrides : {
        '0.0.0.0' : {
          rate  : 0,
          burst : 0
        }
      }
    }));

    server.use(restify.conditionalRequest());

    return server;
github dominiklessel / node-restify-boilerplate / app.js View on Github external
restify.throttle(throttleOptions),
  restify.dateParser(),
  restify.queryParser(),
  restify.fullResponse()
];

if (nconf.get('Security:UseAuth')) {
  plugins.push(require(path.join(__dirname, 'plugins', 'customAuthorizationParser'))());
}

if (nconf.get('Security:UseACL')) {
  plugins.push(require(path.join(__dirname, 'plugins', 'customACLPlugin'))());
}

plugins.push(restify.bodyParser());
plugins.push(restify.gzipResponse());

server.use(plugins);

/**
 * CORS
 */

var corsOptions = {
  origins: nconf.get('CORS:Origins'),
  credentials: nconf.get('CORS:Credentials'),
  headers: nconf.get('CORS:Headers')
};

server.pre(restify.CORS(corsOptions));

if (corsOptions.headers.length) {
github ceejbot / opsbot / lib / server.js View on Github external
assert(opts && _.isObject(opts), 'you must pass an opts argument to Opsbot');
	assert(opts.listen && _.isNumber(opts.listen), 'you must pass a listen port in `opts.listen`');

	this.options = opts;
	this.log = bole('responder');

	this.responder = new Responder(opts);

	var restifyOpts = {};
	var server = restify.createServer(restifyOpts);
	this.client = restify.createJSONClient({ url: opts.hook });

	server.use(restify.acceptParser(server.acceptable));
	server.use(restify.queryParser());
	server.use(logEachRequest);
	server.use(restify.gzipResponse());
	server.use(restify.bodyParser({ mapParams: false }));

	server.get('/ping', this.handlePing.bind(this));
	server.post('/message', this.handleMessage.bind(this));

	this.server = server;
};