Ejemplo n.º 1
0
module.exports = function (app, configurations, express, logger, errorhandler) {

    var nconf = require('nconf');
    var cachify = require('connect-cachify');
    var requestLogger = require('winston-request-logger');
    var bodyParser = require('body-parser');

    nconf.argv().env().file({ file: 'local.json' });

    // load assets node from configuration file.
    var assets = nconf.get('assets') || {}

    var env = process.env.NODE_ENV || 'development';
    if ('development' == env) {
        // register the request logger
        app.use(requestLogger.create(logger));
        app.set('DEBUG', true);
        app.use(errorhandler({ dumpExceptions: true, showStack: true }));
    }
    else if ('production' == env) {
        app.set('DEBUG', false);
        app.use(errorhandler());
    }
    // Cachify Asset Configuration
    app.use(cachify.setup(assets, { root: __dirname + '/public', production: nconf.get('cachify') }));
    app.use(bodyParser.json());
    app.set('views', __dirname + '/views');
    app.set('view engine', 'jade');
    app.locals.pretty = true;
    app.use(express.static(__dirname + '/public'));
    return app;
}
Ejemplo n.º 2
0
SessionStore.create().then(function (sessionStore) {
  const app = express();

  templates.setup(app);

  app.use(logging({ app: app }));

  app.use(express.bodyParser());

  // allow PUT/DELETE methods via POST in HTML forms.
  // requires bodyParser.
  app.use(express.methodOverride());

  app.use(express.cookieParser());

  // requires cookieParser.
  app.use(session({
    sessionStore: sessionStore
  }));

  // requires both cookieParser and bodyParser.
  app.use(csrf());

  app.use(helmet.xframe('deny'));

  if (config.get('ssl')) {
    app.use(helmet.hsts());
  }

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

  app.disable('x-powered-by');

  app.use(helmet.csp({
    'default-src': ['\'self\'', 'https://login.persona.org']
  }));

  app.use(fonts());

  // Get all of our routes.
  app.use(routes);

  // set up cachify before the static middleware to strip off any md5's then
  // serve up the correct gzipped item.
  app.use(cachify.setup({}, {
    root: STATIC_ROOT
  }));

  // Static middleware is last.
  app.use(gzip_static(STATIC_ROOT, { force: true }));

  httpsServer.start({ app: app });
  httpServer.start();
});
Ejemplo n.º 3
0
module.exports = function (app, configurations, express, logger) {

    var nconf = require('nconf')
        , cachify = require('connect-cachify')
        , winston = require('winston')
        , requestLogger = require('winston-request-logger')
        , errorhandler = require('errorhandler')
        , bodyParser = require('body-parser')
        , methodOverride = require('method-override')

    nconf.argv().env().file({ file: 'local.json' })

    // load assets node from configuration file.
    var assets = nconf.get('assets') || {}

    // get the environment, default to development
    var env = process.env.NODE_ENV || 'development';

    // Development Configuration
    if ('development' == env || 'test' == env) {
        // register the request logger
        app.use(requestLogger.create(logger))
        app.set('DEBUG', true)
        //app.use(express.errorHandler({ dumpExceptions: true, showStack: true }))

        // error handling middleware
        app.use(errorhandler())
    }

    // Production Configuration
    if ('production' == env) {
        app.set('DEBUG', false)
        app.use(express.errorHandler())
    }

    // Cachify Asset Configuration
    app.use(cachify.setup(assets, {
        root: __dirname + '/public',
        production: nconf.get('cachify')
    }))

    // Global Configuration
    app.set('views', __dirname + '/views')
    app.set('view engine', 'jade')
    app.set('view options', { layout: false })
    app.use(bodyParser.urlencoded({
        extended: true
    }));
    app.use(bodyParser.json())
    app.use(methodOverride())
    app.use(express.static(__dirname + '/public'))

    return app
}
Ejemplo n.º 4
0
module.exports = function (app, configurations, express, logger) {

    var nconf = require('nconf')
        , cachify = require('connect-cachify')
        , winston = require('winston')
        , requestLogger = require('winston-request-logger')

    nconf.argv().env().file({ file: 'local.json' })

    // load assets node from configuration file.
    var assets = nconf.get('assets') || {}

    // Development Configuration
    app.configure('development', 'test', function(){
        // register the request logger
        app.use(requestLogger.create(logger))
        app.set('DEBUG', true)
        app.use(express.errorHandler({ dumpExceptions: true, showStack: true }))
    })

    // Production Configuration
    app.configure('production', function(){
        app.set('DEBUG', false)
        app.use(express.errorHandler())
    })

    // Cachify Asset Configuration
    app.use(cachify.setup(assets, {
        root: __dirname + '/public',
        production: nconf.get('cachify')
    }))

    // Global Configuration
    app.configure(function(){

        app.set('views', __dirname + '/views')
        app.engine('html', require('ejs').renderFile);
        app.set('view engine', 'ejs')
        app.set('view options', { layout: false })
        app.use(express.bodyParser())
        app.use(express.methodOverride())
        app.use(express.static(__dirname + '/public'))

        app.use(app.router)

    })

    return app
}
Ejemplo n.º 5
0
SessionStore.create().then(function (sessionStore) {
  const app = express();

  templates.setup(app);

  app.use(logging({ app: app }));

  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({ extended: false }));

  // allow PUT/DELETE methods via POST in HTML forms.
  // requires bodyParser.
  app.use(methodOverride());

  app.use(cookieParser());

  // requires cookieParser.
  app.use(session({
    sessionStore: sessionStore
  }));

  // requires both cookieParser and bodyParser.
  app.use(csrf());

  app.disable('x-powered-by');

  app.use(siteQuery);

  // Get all of our routes.
  app.use(routes);

  // set up cachify before the static middleware to strip off any md5's then
  // serve up the correct gzipped item.
  app.use(cachify.setup({}, {
    root: STATIC_ROOT
  }));

  // Static middleware is last.
  app.use(gzip_static(STATIC_ROOT, { force: true }));

  app.use(errorHandler);

  httpServer.start({ app: app });
});
Ejemplo n.º 6
0
var React = require('react');
var Router = require('react-router');
var express = require('express');
var cachify = require('connect-cachify');
var ejs = require('ejs');
var server = express();

// List of assets where the keys are your production urls, and the value
// is a  list of development urls that produce the same asset
var assets = {
  "/app.min.js": [ "/app.js" ]
};

// Enable browser cache and HTTP caching (cache busting, etc.)
server.use(cachify.setup(assets, {
  root: "assets",
  production: (process.env.NODE_ENV != "development")
}));

// Serve static files
// TODO: remember to put the favicon and other relevant stuff there.
server.use('/', express.static('assets'));

// Use Embedded JavaScript to embed the output from React into our layout
server.set('view engine', 'ejs');
server.set('views', 'src/views');

// Require and wrap the React main component in a factory before calling it
// This is necessary because we'll do `App()` instead of <App />
var routes = require("./app.jsx").routes;

// Redirect the user to the list of native components for iOS