How to use the connect.directory function in connect

To help you get started, we’ve selected a few connect 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 yuanyan / hp / index.js View on Github external
//` tiny`  ':method :url :status :res[content-length] - :response-time ms'
        // `dev` concise output colored by response status for development use
        middleware.push( connect.logger({ stream: {
            write: function(str){
                log(str.trim());
            }
        }, format: options.log }) );
    }

    // common middleware
    middleware = middleware.concat([
        // http://www.senchalabs.org/connect/middleware-errorHandler.html
        connect.errorHandler(),
        connect.favicon(),
        connect.static( target ),
        connect.directory( target )
    ]);

    // run server
    return connect.apply(null, middleware)
        .listen(port, function(err) {

            if(err){
                done(err);
            }

            var port = this.address().port;

            // if enable live reload service
            if(options.live){
                var Reactor = require('./lib/reactor');
                // create the reactor object
github adobe / brackets / src / extensions / default / StaticServer / node / StaticServerDomain.js View on Github external
id:         requestId
        };

        // dispatch request event
        _domainManager.emitEvent("staticServer", "requestFilter", [request]);

        // set a timeout if custom responses are not returned
        timeoutId = setTimeout(function () { resume(true); }, _filterRequestTimeout);
    }

    app = connect();
    app.use(rewrite);
    // JSLint complains if we use `connect.static` because static is a
    // reserved word.
    app.use(connect["static"](path, { maxAge: STATIC_CACHE_MAX_AGE }));
    app.use(connect.directory(path));

    server = http.createServer(app);

    // Once the server is listening then verify we can handle requests
    // before calling the callback
    server.on("listening", function () {
        requestRoot(
            server,
            function (err, res) {
                if (err) {
                    createCompleteCallback("Could not GET root after launching server", null);
                } else {
                    createCompleteCallback(null, server);
                }
            }
        );
github modjs / mod / lib / tasks / server.js View on Github external
middleware.push( connect.logger(options.log) );
    }

    // delay response config
    if(options.delay){
       middleware.push( delay(options, connect));
        exports.log("delay service enable");
    }

    // common middleware
    middleware = middleware.concat([
        // http://www.senchalabs.org/connect/middleware-errorHandler.html
        connect.errorHandler(),
        connect.favicon(),
        connect.static( target ),
        connect.directory( target )
    ]);


    // run server
    connect.apply(null, middleware)
        .on('error', function( err ) {
            if ( err.code === 'EADDRINUSE' ) {
                return this.listen(0); // 0 means random port
            }

            // not an EADDRINUSE error, buble up the error
            done(err);
        })
        .listen(port, function(err) {

            if(err){
github remy / 5minutefork / index.js View on Github external
function createRoute(dir) {
  return connect()
    .use(connect.static(dir))
    .use(connect.directory(dir))
    .use(function (req, res) {
      // if we hit this point, then we have a 404
      res.writeHead(404, { 'content-type': 'text/html' });
      res.end(error);
    });
}
github oniproject / oniproject / gulpfile.js View on Github external
gulp.task('server', function(next) {
	var connect = require('connect');
	connect()
		.use(connect.static('./'))
		.use(connect.static('public'))
		.use(connect.directory('public'))
		.use(function(req, res) {
			if (req.method == 'POST') {
				console.log(req.body);
			} else {
				res.end('FUCK U\n');
			}
		})
		.listen(process.env.PORT || 9000, next);
});
github dpwoert / CityIO / gulpfile.js View on Github external
gulp.task('demos/denBosch', function() {

    var connect = require('connect');
    var app = connect()
        .use(connect.static('demos/denBosch'))
        .use(connect.static('export'))
        .use(connect.directory('demos/denBosch'));

    require('http').createServer(app)
        .listen(9000)
        .on('listening', function () {
            console.log('Started connect web server on http://localhost:9000');
        });

});
github hswolff / hn-ng / gulpfile.js View on Github external
gulp.task('connect', function () {
    var connect = require('connect');
    var app = connect()
        .use(require('connect-livereload')({ port: 35729 }))
        .use(connect.static('.tmp'))
        .use(connect.static('app'))
        .use(connect.directory('app'));

    require('http').createServer(app)
        .listen(9000)
        .on('listening', function () {
            console.log('Started connect web server on http://localhost:9000');
        });
});
github kvz / metriks / lib / web-server.js View on Github external
WebServer.prototype.start = function () {
  var self   = this;
  var server = connect();
  server.use(connect.static(self.pngDir, {
    hidden: false
  }));
  server.use(connect.directory(self.pngDir, {

  }));
  server.listen(self.webPort, function () {
    self.cli.info(util.format(
      'Serving %s on port %s',
      self.pngDir,
      self.webPort
    ));
  });
};
github tgvashworth / distra / distra.js View on Github external
var createStaticServer = function (path) {
  var server = connect();
  server.use(gzippo.staticGzip(path, { maxAge: 0 }))
        .use(connect.directory(path));
  return server;
};
github spmjs / spm / lib / actions / server.js View on Github external
async.series([loadConfig, cacheConfig], function() {
    var app = connect().
        use(manageConfigCache).
        use(getInfoJson).
        use(connect.query()).
        use(proxyModule).
        use(addModule).
        use(beautify).
        use(connect.static(fileDir, {'maxAge': 200 * 1000})).
        use(connect.directory(fileDir)).
        use(connect.errorHandler()).
        listen(argv.port);
  });
};