Exemple #1
0
module.exports = function(app) {

  var express = require('express'),
      router = express.Router(),
      serveIndex = require('serve-index'),
      secure = require('../middleware/secure'),
      notFound = require('../middleware/not-found'),
      errHandler = require('../middleware/err-handler'),
      indexOpts = { icons: true, view: 'details' },
      web = __dirname+'/../web';

  app.set('views', web);
  app.set('view engine', 'ejs');

  router.use('/private',
      secure.https,
      secure.auth,
      serveIndex(web + '/private', indexOpts));

  router.use('/public',
      serveIndex(web + '/public', indexOpts));

  router.use('/docs',
      secure.https,
      secure.auth);

  router.use('/',
      express.static(web),
      notFound,
      errHandler.forHtml);

  return router;
}
var Server = function(dir, port){
  var app = connect();
  app.use(function (req, res, next) {
    res.setHeader("Access-Control-Allow-Origin", "*");
    next();
  });

  app.use(serveStatic(dir, {'index': ['index.html']}));
  app.use(serveIndex(dir, {'icons': true}));

  // anywhere 8888
  // anywhere -p 8989
  // anywhere 8888 -s // silent
  // anywhere -h localhost
  // anywhere -d /home
  var port = port || argv._[0] || argv.port;
  var hostname = argv.hostname || getIPAddress();


  app.listen(port, function () {
    // 忽略80端口
    port = (port != '80' ? ':' + port : '');
    var url = "http://" + hostname + port + '/';
    console.log("Running at " + url);
    if (!argv.silent) {
      //openURL(url);
      autoBrowser(url);
    }
  });
};
Exemple #3
0
  photosRouter.get('/', function(req, res) {
    serveIndex('public/assets/')(req, res);

    /*res.send({
      'photos': []
    });*/
  });
Exemple #4
0
app.use('/pages/:namespace/:project/*', function(req, res, next) {
    // Serve directory indexes for public/ftp folder (with icons)
    var p = req.originalUrl.replace(/^\/pages\//, '');
    var dir = path.join(config.deploy.publicPagesDir, p);
    var index = serveIndex(dir, {'icons': true})
    index(req, res, next);
});
Exemple #5
0
module.exports = function serve(options){
    console.log('SERVING', options.port);
    console.log('watch', options.watch);
    console.log('directory', options.directory);
    console.log('open', options.open);

    if(options.watch){
        var watchPath = path.join(options.watch, '/**/*');
        console.log('watching', watchPath);
        var gaze = new Gaze(watchPath);
        // Files have all started watching
        gaze.on('ready', function(watcher) { });

        // A file has been added/changed/deleted has occurred
        gaze.on('all', function(event, filepath) {
            var cmd = options.exec;
            console.log('WE SHOULD TRIGGER BUILD', cmd);
            var exec = require('child_process').exec;
            exec(cmd);
        });
    }

    live = instant(options.directory/*{
        // delay: 200,
        root: options.directory
    }*/);

    app.use(live)
        .use(serveIndex(options.directory, { icons: true, hidden: true }))
        .listen(options.port, function() {
            current = '/';
            var listening = this.address().port;
            if(options.open) open('http://localhost:' + listening);
        });
};
Exemple #6
0
paths.split(',').forEach(function(pth) {
  // Serve static files that exist
  app.use(serveStatic(path.join(process.cwd(), pth)));
  // Serve directory listings
  app.use(serveIndex(path.join(process.cwd(), pth),
    {'icons':true,'view':'details'}));
});
  serveIndex: function (req, res, next) {
    if (!req.isDirectory) {
      next()
      return
    }

    const originalUrl = req.url
    const _drive = drive(req.url)
    req.url = urlWithoutDrive(req.url)

    serveIndex(_drive, { icons: true,
      filter: function (f) {
        if (!req._config.filter) {
          return f
        } else { // filter only markdown files
          const stats = fs.statSync(uri2filename(originalUrl + '/' + f))
          if (!stats.isFile() || MARKDOWNEXT.test(f)) {
            return f
          }
        }
      }
    })(req, res, function (err) {
      req.url = originalUrl
      next(err)
    })
  },
  gulp.task('connect', ['build'], function() {
    var devCompiler = webpack(webpackDevConfig)
    var express = require('express')
    var serveStatic = require('serve-static')
    var serveIndex = require('serve-index')
    var bodyParser = require('body-parser')

    $.livereload.listen(35729, function() {
      console.log('Listening on', 35729)
    })

    var app = express()
    app
    .use(bodyParser.json())
    //.use(require('connect-livereload')())
    .use(webpackDevMiddleware(devCompiler, {
      contentBase: './app/',
      publicPath: webpackConfig.output.publicPath,
      stats: {
        colors: true
      }
    }))
    .use(serveStatic('app'))
    .use(serveStatic('.tmp'))
    .use(serveIndex('app'))

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

	var express = require('express'); // charge ExpressJS
	var serveIndex = require('serve-index');

	var app = express();

	app.use('/ws/', function(req, res, next) {
		console.log('req.url wait for 2s', req.url);
		setTimeout(function() {
			next();
		}, 2000);
	});
	
	app.use(express.static('.'));
	app.use(serveIndex('.', {icons: true}));

	app.use(function(req, res, next) {
		console.log('404: Page not Found', req.url);
		next();
	});

	app.listen(8000, function() {
		console.log('server started on port 8000');
	});
})();
Exemple #10
0
 httpApp.use('/', (req, res, next) => {
   if (req.headers['accept'] === 'application/json') {
     return serveIndex(rootDirectory,
         {icons: true, template: TEMPLATE_PATH, stylesheet: STYLESHEET_PATH})(req, res, next);
   } else {
     NotFoundPage(req, res); // Actual not found content
   }
 });
Exemple #11
0
gulp.task('develop', [], function(callback)
{
    var serveStatic = require('serve-static');
    var serveIndex = require('serve-index');
    var app = require('connect')()
        .use(serveStatic(WEB_DIRECTORY))
        .use(serveIndex(WEB_DIRECTORY));
    require('http').createServer(app).listen(PORT);
});
Exemple #12
0
 var lrMiddleware = function(connect, options, middlwares) {
     return [
         lrSnippet,
         // 静态文件服务器的路径 原先写法:connect.static(options.base[0])
         serveStatic(options.base[0]),
         // 启用目录浏览(相当于IIS中的目录浏览) 原先写法:connect.directory(options.base[0])
         serveIndex(options.base[0])
     ];
 };
 'middleware' : function (req, res, next) {
     index(reportsDir, { 
         'filter'     : false,
         'hidden'     : true,
         'icons'      : true,
         'stylesheet' : false,
         'template'   : false,
         'view'       : 'details'
     })(req, res, next);
 }
gulp.task('watch', function () {
  var app = express();
  app.use(express.static('./'));
  app.use(directory('./'));
  app.listen(8090);
  browser('http://localhost:8090/demo.html', 'Google Chrome');

  gulp.watch(['src/*.less'], ['less']);
  gulp.watch(['src/*.js'], ['scripts', 'lint']);
});
gulp.task('start-server', ['build'], function(cb) {
  express()
    .use(serveIndex(__dirname + '/out'))
    .use(serveStatic(__dirname + '/out'))
    .listen(config.port, function() {
      console.log('Listening on port %s...', config.port);
    });

  cb(null);
});
Exemple #16
0
  /**
   * data = {
   *   path,
   *   target,
   *   fileOptions: {
   *     redirect,
   *     maxAge,
   *   },
   *   directoryOptions: {
   *     icons,
   *     view,
   *   },
   *  }
   */
  constructor(data) {
    //super(context, data);

    // Set up serveStatic and indexStatic promise functions.
    this.serveStatic = serveStatic(data.target, merge({redirect: false, maxAge: '1d'}, data.fileOptions || {}));
    this.serveIndex = data.directoryOptions ? serveIndex(data.target, merge({icons: true, view: 'details'}, data.directoryOptions)) : undefined;
    this.path = data.path;
    this.target = data.target;
    this.data = data;
  }
 var lrMiddleware = function(connect, options) {
   return [
     // 把脚本,注入到静态文件中
     lrSnippet,
     // 静态文件服务器的路径
     serveStatic(options.base[0]),
     // 启用目录浏览(相当于IIS中的目录浏览)
     serveIndex(options.base[0])
   ];
 };
Exemple #18
0
        roomList.forEach(roomName => {
            const roomPath = roomConfig.getRoomPath(roomName);
            const staticPath = path.resolve(__dirname, `../rooms/${roomName}/static`);

            console.log('Static: ', roomPath, staticPath);

            app.use(roomPath, express.static(staticPath));
            app.use(roomPath, serveIndex(staticPath));

        });
gulp.task('webserver', function () {
    //start up the server
    app = connect()
        // Serve files from /app
        .use(serveStatic(path.resolve(config.dirs.app)))
        // Serve the main.css that resides in /.tmp
        .use(serveStatic(path.resolve(config.dirs.tmp), {'dotfile': 'allow'}))
        // Serve the index.html
        .use(serveIndex(path.resolve(config.dirs.app)));
    http.createServer(app).listen(8080);
});
gulp.task('develop', [], function(callback)
{
    gulp.src(['Application.js'], {base: './'}).pipe(gulp.dest(WEB_DIRECTORY));
    gulp.src(['index-dev.html'], {base: './'}).pipe(rename('index.html')).pipe(gulp.dest(WEB_DIRECTORY));
    var serveStatic = require('serve-static');
    var serveIndex = require('serve-index');
    var app = require('connect')()
        .use(serveStatic(WEB_DIRECTORY))
        .use(serveIndex(WEB_DIRECTORY));
    require('http').createServer(app).listen(PORT);
});
Exemple #21
0
 middleware: function(connect, options) {
   var base = Array.isArray(options.base) ? options.base[options.base.length - 1] : options.base;
   return [
     util.conditionalCsp(),
     util.rewrite(),
     e2e.middleware(),
     serveFavicon('images/favicon.ico'),
     serveStatic(base),
     serveIndex(base)
   ];
 }
Exemple #22
0
exec('pwd', function(err, stdout) {
  var cwd = stdout;
  cwd = cwd.replace('\n','');

  var app = connect();

  app.use(serveStatic(cwd));
  app.use(serveIndex(cwd, {'icons': true}))
  app.listen(port);
	
  console.log('Static server started on http://localhost:' + port + ' \nserving: ' + cwd);
});
Exemple #23
0
gulp.task('dev-jasmine-server', function (done) {

    var server = connect();
    server.use(serveStatic('target/reports/jasmine'));
    server.use(serveIndex('target/reports/jasmine'));

    jasmineServer = server.listen(settings.servers.jasmine.port, settings.servers.jasmine.host, function () {
        console.log('Jasmine running on ' + settings.servers.jasmine.host + ':' + settings.servers.jasmine.port);
        done();
    });

});
Exemple #24
0
gulp.task('connect', function () {
  var app = connect()
    .use(connectreload({port: 35729}))
    .use(serveStatic('./'))
    .use(serveIndex('./example/example.html'));

  require('http').createServer(app)
    .listen(9000)
    .on('listening', function () {
      console.log('Started connect web server on http://localhost:9000/example/example.html');
    });
});
Exemple #25
0
OpenBrowser.prototype._initServer = function() {
  var self = this;
  self.app = connect();
  // 是否输入日志
  !self.silent && self.app.use(logger());

  self.app.use(header(self.headers))
    .use(combo({
      ip: self.ip,
      port: self.port
    }))
    .use(function(req, res, next) {
      var ob = {
        ip: self.ip,
        port: self.port,
        root: self.root,
        config: self.config || {},
        php: self.php,
        req: req,
        res: res,
        handler: require('./handler')
      };
      ob.handler().then(function(data) {
        data.body ? res.end(data.body) : next();
      }).catch(function(err) {
        next();
      });
    })
    .use(serveIndex(self.root, {'icons': true}))
    .use(ecstatic({
      root: self.root,
      showDir: self.showDir,
      cache: self.cache,
      autoIndex: self.autoIndex,
      defaultExt: self.ext
    }))
    .use(errorhandler());

  self.server = http.createServer(self.app);
  // 绑定事件
  self._bindEvent();

  // php 服务器
  phpserver.createServer(function(server, port) {
    if (server && port) {
      self.php = {
        server: server,
        port: port
      };
    }
  });
};
Exemple #26
0
(function() {
	'use strict';

	var express = require('express'); // charge ExpressJS
	var serveIndex = require('serve-index');

	var app = express();
	
	app.use(function(req, res, next) {
		console.log('url: ', req.url);
		next();
	});

	app.use(express.static('.'));
	app.use(serveIndex('.', {icons: true}));
	
	app.get('/ws/herve', function(req, res) {
		setTimeout(function() {
			res.json({prenom: 'Hervé'});
		}, 1000);
	});
	
	app.get('/ws/philippe', function(req, res) {
		setTimeout(function() {
			res.json({prenom: 'Philippe'});
		}, 2000);
	});
	
	app.get('/ws/fabien', function(req, res) {
		setTimeout(function() {
			res.json({prenom: 'Fabien'});
			//res.sendStatus(500);
		}, 3000);
		
	});
	
	app.get('/ws/marcel', function(req, res) {
		setTimeout(function() {
			res.json({prenom: 'Marcel'});
		}, 2000);
		
	});

	app.use(function(req, res, next) {
		console.log('404: Page not Found', req.url);
		next();
	});

	app.listen(8000, function() {
		console.log('server started on port 8000');
	});
})();
     .update("middleware", function (mw) {
     if (!server.get("directory")) {
         return mw;
     }
     return mw.concat({
         route: "",
         handle: serveIndex(resolve(basedirs[0]), {
             icons: true,
             view: "details"
         }),
         id: "Browsersync Server Directory Middleware"
     });
 })
Exemple #28
0
app.middleware = function(options) {
  options = options || {};

  app.set('base', options.base);

  if (options.base) {
    debug('Init directory viewer', options.base);
    app.use(directory(options.base));
    app.use(express.static(options.base));
  }

  return app;
};
gulp.task('connect', ['styles'], function () {
  var app = connect()
    .use(require('connect-livereload')({port: 35729}))
    .use(serveStatic('app'))
    .use('/bower_components', serveStatic('bower_components'))
    .use(serveIndex('app'));

  require('http').createServer(app)
    .listen(9000)
    .on('listening', function () {
      console.log('Started connect web server on http://localhost:9000');
    });
});
gulp.task('connect', function() {
  var serveStatic = require('serve-static');
  var serveIndex = require('serve-index');
  var app = require('connect')().use(require('connect-livereload')({
      port: 35729
    })).use(serveStatic('.tmp')).use(serveStatic('app'))
    // paths to bower_components should be relative to the current file
    // e.g. in app/index.html you should use ../bower_components
    .use('/bower_components', serveStatic('bower_components')).use(serveIndex('app'));
  require('http').createServer(app).listen(config.PORT_DEV).on('listening', function() {
    console.log('Started connect web server on http://localhost:' + config.PORT_DEV);
  });
});