How to use the express.staticProvider 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 rauchg / jsconf-todo-demo / server.js View on Github external
getters: {
    id: function(){
      return this._id.toHexString();
    },
    
    description_formatted: function(v){
      return this.description ? '<p>' + this.description.replace(/\n/g, '</p><p>') + '</p>' : '';
    }
  }
  
});

// app initialization
var app = express.createServer(
  express.staticProvider(__dirname + '/public'),
  express.bodyDecoder(),
  express.cookieDecoder(),
  express.session()
);

app.configure(function(){
  Item = db.model('Item');
});

// routes
app.get('/', function(req, res){
  
  Item.find({}).sort([['_id', -1]]).all(function(items){
    res.render('index.jade', {locals: {items: items, connections: connections}, layout: false});
  });
github cutting-room-floor / tilestream / server / ui-server.js View on Github external
'handlebars/handlebars.js',
        'bones/bones.js',
        'openlayers_slim/OpenLayers.js',
        'wax/build/wax.ol.min.js',
        'tilestream/mvc/models.js',
        'tilestream/mvc/views.js',
        'tilestream/mvc/controllers.js',
        'tilestream/client/js/app.js'
    ]));
    server.get('/css/vendor.css', mirror.assets([
        'tilestream/client/css/reset.css',
        'tilestream/client/css/controls.css',
        'tilestream/client/css/style.css',
    ], {'Content-Type': 'text/css'}));
    server.get('/theme/default/style.css', mirror.file('openlayers_slim/theme/default/style.css'));
    server.use(express.staticProvider(path.join(__dirname, '..', 'client')));

    // Settings endpoint. Send information that need to be shared between
    // server/client.
    server.get('/settings.js', function(req, res, next) {
        res.send(
            'var Bones = Bones || {};\n' +
            'Bones.settings = ' + JSON.stringify(req.model.options) + ';',
            { 'Content-Type': 'text/javascript' }
        );
    });

    // Add map wax endpoint.
    require('./wax')(server, settings);

    // Route middleware for validating a model.
    function validateModel(req, res, next) {
github maritz / nohm / admin / app.js View on Github external
Ni.controllers.home = Ni.controllers.Models;
  
  // initialize the main app
  var app = express.createServer();
  app.set('view engine', 'jade');

  if (app.set('env') !== 'production') {
    app.use(express.lint(app));
  }

  // static stuff
  app.use(express.conditionalGet());
  app.use(express.favicon(''));
  app.use(express.gzip());
  app.use(express.staticProvider(__dirname + '/public'));

  // start main app pre-routing stuff
  app.use(express.bodyDecoder());
  app.use(express.cookieDecoder());
  var redisSessionStore = new RedisStore({magAge: 60000 * 60 * 24, port: Ni.config('redis_port')}); // one day
  redisSessionStore.client.select(Ni.config('redis_session_db'), function () {
    
    app.use(express.session({
      key: Ni.config('cookie_key'),
      secret: Ni.config('cookie_secret'),
      store: redisSessionStore}));
    
    
    app.use(function (req, res, next) {
      res.original_render = res.render;
      res.rlocals = {};
github ciaranj / connect-auth / examples / mac / app.js View on Github external
server.configure(function () {

        // Built-in

        server.use(express.methodOverride());                           // Allow method override using _method form parameter
        server.use(express.bodyDecoder()); 	                            // Parse application/x-www-form-urlencoded
        server.use(express.staticProvider(__dirname + '/files'));       // Serve client documents in local directory

        // Local

        server.use(setResponseHeader());                                // Set default response headers for CORS
        server.use(logConsole());                                       // Display incoming requests

        // Authentication

        server.use(auth([auth.Mac({ realm: "Example",                   // Set realm, typically a domain name or application name
                                    getTokenAttributes: getToken,       // Function used to fetch the access token record, typically from a database
                                    // hostHeader: 'x-forwarded-host',  // Needed when running behind a proxy such as Apache2
                                    // isHTTPS: true,                   // Uncomment for HTTPS
                                    checkNonce: nonceCheck,             // Optional nonce checking function
                                    bodyHashMode: "require" })]));      // Require body hash validation for all non GET/HEAD/OPTIONS requests
    });
github joyent / node-camp / blog / server.js View on Github external
app.configure(function(){
  app.set('name', 'My cool blog');
  app.set('views', __dirname + '/views');
  app.set('view engine', 'jade');
  app.use(express.cookieDecoder());
  app.use(express.session())
  app.use(express.bodyDecoder());
  app.use(express.methodOverride());
  app.use(app.router);
  app.use(express.staticProvider(__dirname + '/public'));
});
github mgutz / backbone-knockout-examples / app.js View on Github external
app.configure(function(){
  app.set('views', __dirname + '/views');
  app.set('view engine', 'ejs');
  app.use(express.bodyDecoder());
  app.use(express.methodOverride());
  app.use(express.compiler({ src: __dirname + '/public', enable: ['less'] }));
  app.use(app.router);
  app.use(express.staticProvider(__dirname + '/public'));
});
github davglass / yui-express / server.js View on Github external
app.configure(function(){
        //app.use(YUI.express);

        app.use(extras.fixIP());
        app.use(extras.throttle({ holdTime: 5 }));

        app.use(express.favicon(__dirname + '/assets/favicon.ico'));
        app.use(express.logger());
        app.use(express.methodOverride());
        if (express.bodyDecoder) {
            app.use(express.bodyDecoder());
            app.use(express.cookieDecoder());        
            app.use(express.conditionalGet());
            app.use(express.cache());
            app.use(express.gzip());
            app.use(express.staticProvider(__dirname + '/assets'));
        } else {
            app.use(function(req, res, next) {
                res.partial = function(name) {
                    return fs.readFileSync(path.join(__dirname, 'views', 'partials', name), encoding='utf8');
                };
                next();
            });
            app.use(express.bodyParser());
            app.use(express.cookieParser());        
            app.use(express.static(__dirname + '/assets'));
        }
        app.use(app.router);
    });
github chadhutchins / node-trends / app.js View on Github external
app.configure(function(){
  app.use(express.logger('\x1b[33m:method\x1b[0m \x1b[32m:url\x1b[0m :response-time'));
  app.use(express.bodyDecoder());
  app.use(express.methodOverride());
  app.use(express.cookieDecoder());
  app.use(express.session({ secret: 'keyboard cat' }));
  app.use(app.router);
  app.use(express.staticProvider(__dirname + '/public'));
  app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
  
  app.set('view engine', 'haml');
  app.register('.haml', require('hamljs'));
});