How to use the express.compress function in express

To help you get started, we’ve selected a few express 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 Fauntleroy / tandem.io_2014-2016 / index.js View on Github external
server.use( express_session({
	secret: SESSION_SECRET,
	cookie: {
		maxAge: 1000 * 60 * 60 * 24 * 14 // 2 weeks from now
	},
	store: new RedisStore({
		host: parsed_redis_connection_url.hostname,
		port: parsed_redis_connection_url.port,
		pass: (parsed_redis_connection_url.auth || '').split(':')[1]
	}),
	resave: false,
	saveUninitialized: true
}) );

// Compress responses
server.use( express.compress() );

// Static file serving
server.use( express.static( __dirname + '/assets' ) );

// Socket.io configuration
io.use( function( socket, next ){
	var auth_data = _.pick( socket.request._query, 'id', 'name', 'avatar', 'token' );
	var is_authentic = ( generateAuthToken( auth_data.id, auth_data.name, auth_data.avatar ) === auth_data.token );
	if( !is_authentic ){
		next( new Error('Invalid user token') );
		return;
	}
	socket.auth_data = auth_data;
	next();
});
github fangli / kibana-authentication-proxy / app.js View on Github external
// Authentication
require('./lib/basic-auth').configureBasic(express, app, config);
require('./lib/google-oauth').configureOAuth(express, app, config);
require('./lib/cas-auth.js').configureCas(express, app, config);

// Setup ES proxy
require('./lib/es-proxy').configureESProxy(app, config.es_host, config.es_port,
          config.es_username, config.es_password);

// Serve config.js for kibana3
// We should use special config.js for the frontend and point the ES to __es/
app.get('/config.js', kibana3configjs);

// Serve all kibana3 frontend files
app.use(express.compress());
app.use('/', express.static(__dirname + '/kibana/src', {maxAge: config.brower_cache_maxage || 0}));


run();

function run() {
  if (config.enable_ssl_port === true) {
    var options = {
      key: fs.readFileSync(config.ssl_key_file),
      cert: fs.readFileSync(config.ssl_cert_file),
    };
    https.createServer(options, app).listen(config.listen_port_ssl);
    console.log('Server listening on ' + config.listen_port_ssl + '(SSL)');
  }
  http.createServer(app).listen(config.listen_port);
  console.log('Server listening on ' + config.listen_port);
github Esri / node-geoservices-adaptor / index.js View on Github external
app.configure(function() {
	app.use(express.compress());
	app.use(express.methodOverride());
	app.use(express.bodyParser());
 
	// ## CORS middleware
	//
	// see: http://stackoverflow.com/questions/7067966/how-to-allow-cors-in-express-nodejs
	var allowCrossDomain = function(req, res, next) {
		res.header('Access-Control-Allow-Origin', '*');
		res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
		res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization');
		// intercept OPTIONS method
		if ('OPTIONS' == req.method) {
			res.send(200);
		}
		else {
			next();
github derbyjs / derby / bin / default-js / lib / server / index.js View on Github external
var store = derby.createStore({
  db: liveDbMongo(mongoUrl + '?auto_reconnect', {safe: true})
, redis: redis
});

function createUserId(req, res, next) {
  var model = req.getModel();
  var userId = req.session.userId || (req.session.userId = model.id());
  model.set('_session.userId', userId);
  next();
}

expressApp
  .use(express.favicon())
  // Gzip dynamically
  .use(express.compress())
  // Respond to requests for application script bundles
  .use($$app$$.scripts(store))
  // Serve static files from the public directory
  // .use(express.static(__dirname + '/../../public'))

  // Add browserchannel client-side scripts to model bundles created by store,
  // and return middleware for responding to remote client messages
  .use(racerBrowserChannel(store))
  // Add req.getModel() method
  .use(store.modelMiddleware())

  // Parse form data
  // .use(express.bodyParser())
  // .use(express.methodOverride())

  // Session middleware
github XervoIO / express-static-example / app.js View on Github external
var express = require('express');
var app = express();

// The number of milliseconds in one day
var oneDay = 86400000;

// Use compress middleware to gzip content
app.use(express.compress());

// Serve up content from public directory
app.use(express.static(__dirname + '/public', { maxAge: oneDay }));

app.listen(process.env.PORT || 3000);
github cbumgard / node-boot / app.js View on Github external
app.configure(function() {
  app.use(express.logger({format: config.logging.express_format}));  
  app.use(express.compress()); // use gzip compression on static assets
  app.set('views', __dirname + '/views');
  app.set('view engine', 'jade');
  app.set('view options', {layout: false});
  app.use(express.cookieParser());
  app.use(express.bodyParser());
  app.use(express.methodOverride());
  if (config.logging.winston_mongodb) {
    logger.remove(logger.transports.Console);
    require('winston-mongodb').MongoDB; // mongo transport for winston logging
    logger.add(logger.transports.MongoDB, config.logging.winston_mongodb);
    // Consider letting Winstong log transport handle uncaught exceptions: https://github.com/flatiron/winston#handling-uncaught-exceptions-with-winston
  }    
  if (config.redis) {
    logger.info('Connecting to Redis at ' 
      + config.redis.session_opts.host + ':' 
      + config.redis.session_opts.port);
github bloodyowl / craft / test / server.js View on Github external
app.configure(function(){
    app.use(express.compress())
    app.set("port", port)
    app.use(express.bodyParser())
    app.use(express.logger("dev"))
    app.use(express.static(path.join(__dirname, '../')))
  })
github mozilla / MakeAPI / server.js View on Github external
app.use(express.logger("dev"));
}

app.use(express.favicon("public/images/favicon.ico", {
  maxAge: 31556952000
}));

app.use(helmet.iexss());
app.use(helmet.contentTypeOptions());
app.use(helmet.xframe());

if (!!env.get("FORCE_SSL")) {
  app.use(helmet.hsts());
  app.enable("trust proxy");
}
app.use(express.compress());
app.use(express.static(path.join(__dirname + "/public")));
app.use(express.json());
app.use(express.urlencoded());
app.use(webmakerAuth.cookieParser());
app.use(webmakerAuth.cookieSession());

var optimize = env.get("NODE_ENV") !== "development",
  tmpDir = path.join(require("os").tmpDir(), "makeapi.webmaker.org");
app.use(lessMiddleware({
  once: optimize,
  debug: !optimize,
  dest: tmpDir,
  src: path.resolve(__dirname, "public"),
  compress: optimize,
  yuicompress: optimize,
  optimization: optimize ? 0 : 2,
github MMODM / mmodm / app.js View on Github external
function startSlave(){
    var app = express();
    var http = require('http').Server(app);
    var io = require('socket.io')(http);

    addRedisAdapter(io);
    addIOEventHandlers(io);

    app.set('port', port);
    app.set('views', __dirname + '/views');
    app.set('view engine', 'jade');
    app.use(express.compress());
    app.use(express.favicon());
    app.use(express.cookieParser());
    app.use(express.session({ secret: config.session_secret }));
    app.use(express.bodyParser());
    app.use(express.methodOverride());
    app.use(function (req, res, next) {
        res.header("X-powered-by", "The Force")
        next()
    })
    app.use(app.router);
    app.use(express.static(path.join(__dirname, 'public'),{ maxAge: 2629800000 }));
    app.use(express.logger());
    app.use(express.errorHandler())

    //Routes
    app.get('/', routes.index);
github rendrjs / rendr-examples / 06_appview / index.js View on Github external
var express = require('express')
  , rendr = require('rendr')
  , app = express();

/**
 * Initialize Express middleware stack.
 */
app.use(express.compress());
app.use(express.static(__dirname + '/public'));
app.use(express.logger());
app.use(express.bodyParser());

/**
 * In this simple example, the DataAdapter config, which specifies host, port, etc. of the API
 * to hit, is written inline. In a real world example, you would probably move this out to a
 * config file. Also, if you want more control over the fetching of data, you can pass your own
 * `dataAdapter` object to the call to `rendr.createServer()`.
 */
var dataAdapterConfig = {
  'default': {
    host: 'api.github.com',
    protocol: 'https'
  },
  'travis-ci': {