middleware: function (connect) {
     return [
         proxyRequest,
         livereload({port: 8010}),
         mountFolder(connect, settings.dir.cordova + '/platforms')
     ];
 }
Example #2
0
 middleware: function (connect) {
     return [
         connect_livereload({port: ports.livereload}),
         mount(connect, dirs.stress.build),
         mount(connect, dirs.stress.root)
     ];
 }
module.exports = function asyncStartHTTP(options) {

    // create random port for live-reload server
    var r = 37331;//Math.floor(Math.random()*10000) + 30000;

    // defaults
    var opts = _.defaults(options, {
        app_port: 3004,
        livereload_port: r,
        rootPath: 'dist/',
        middlewares: []
    });

    opts.callback = opts.callback || function onSuccess() {
        console.log(
            'App server started at http://localhost:' + opts.app_port,
            '\n\t~> LR server http://localhost:' + opts.livereload_port);
    }

    // content
    var e = express()
        .use(connectLR({port: opts.livereload_port}))
        .use(express.static(path.resolve(opts.rootPath)));

    // add middlewares
    e = _.reduce(opts.middlewares, function(accum, middleware) {
            return accum.use(middleware)
        }, e);

    // start server
    e.listen(opts.app_port, opts.callback);

    // start livereload server
    livereload.listen(opts.livereload_port);
};
exports.init = function (server) {
  var morgan = require('morgan'), // For logging
      favicon = require('serve-favicon'), // For serving our favicon
      bodyParser = require('body-parser'), // For parsing urlencoded and json request bodies
      cookieParser = require('cookie-parser'),
      session = require('express-session'),
      MongoStore = require('connect-mongo')(session),
      database = require('../database/database'),
      liveReload = require('connect-livereload'),
      staticFiles = require('./static-files');

  // Set up the templating engine
  server.set('views', __dirname);
  server.set('view engine', 'ejs');

  server.use(morgan('dev', {immediate: true}));
  server.use(favicon(config.faviconPath));
  server.use(bodyParser.json());
  server.use(cookieParser());
//  server.use(session({
//    secret: config.app.sessionSecret,
//    store: new MongoStore({
//      mongoose_connection: database.getDatabaseConnection(),
//      collection: 'sessions'
//    })
//  }));
  server.use(liveReload({port: config.app.liveReloadPort}));

  staticFiles.init(server);
};
Example #5
0
gulp.task('serve.preboot', function() {
// todo: refactor to better fit in with rest of gulp script

  var express = require('express');
  var livereload = require('connect-livereload');
  var reloader = require('gulp-livereload');
  var serveStatic = require('serve-static');
  var exec = require('child_process').exec;
  var open = require('open');
  var server = express();
  var LIVERELOAD_PORT = 35729;
  var PORT = 3000;

  server.use(livereload({
    port: LIVERELOAD_PORT
  }));

  server.use(serveStatic('dist'));
  server.use(serveStatic('examples'));

  server.listen(PORT);
  reloader.listen({
    port: LIVERELOAD_PORT,
    reloadPage: '/preboot/preboot_example.html'
  });
  open('http://localhost:3000/preboot/preboot_example.html');

  exec('tsc -w');
  gulp.watch('modules/preboot/**/*', [ 'build']);
  gulp.watch('dist/preboot/preboot.js', function () {
    reloader.reload();
  });

});
Example #6
0
app.configure('development', function() {
  console.log('configuring as development server');
  // live reload script (adds js snippet, but doesn't host server)
  if (process.env[LIVERELOAD_PORT]) app.use(livereload({ port: process.env[LIVERELOAD_PORT] }));

  app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
gulp.task('serve', function() {
  expressServer =
    express()
    .use(!build ? connectLr() : function(){})
    .use(express.static(targetDir))
    .listen(port);
});
Example #8
0
  gulp.task('example', [ 'example.build' ], function() {
    var express = require('express');
    var livereload = require('connect-livereload');
    var reloader = require('gulp-livereload');
    var serveStatic = require('serve-static');
    var exec = require('child_process').exec;
    var open = require('open');
    var server = express();
    var LIVERELOAD_PORT = 35729;
    var PORT = 3000;

    server.use(livereload({
      port: LIVERELOAD_PORT
    }));

    server.use(serveStatic('dist/example'));

    server.listen(PORT);
    reloader.listen({
      port: LIVERELOAD_PORT,
      reloadPage: '/preboot_example.html'
    });
    open('http://localhost:3000/preboot_example.html');

    exec('tsc -w');
    gulp.watch(opts.tsFiles, [ 'example.build' ]);
    gulp.watch('dist/example/preboot.js', function () {
      reloader.reload();
    });
  });
Example #9
0
module.exports      = function (app) {

      app.use(  bodyParser
        .urlencoded({extended:false}) );
      if(process.env.NODE_ENV === 'development'){
        app.use(  reloader()   );


      }
      app.use(  bodyParser.json()     );
      app.use(  methodOverride()      );
      // app.use(  morgan('dev')         );

      // Root path of server
      //
      app.set('root', path.normalize(__dirname + '/../..') );

      // Server port
      //
      app.set('port', process.env.PORT || 9000);

      // Set environment Variables
      //
      environment.runEnvironment(app);

};
Example #10
0
gulp.task('server', function(){
  express()
    .use(express_lr())
    .use(express.static('.'))
    .listen(Config.port);
  gutil.log('Server listening on port ' + Config.port);
});
Example #11
0
 return function () {
   var middleware = o.middleware ? o.middleware.call(this, connect, o) : [];
   if (o.livereload) {
     if (typeof o.livereload == 'boolean') o.livereload = {};
     if (!o.livereload.port) o.livereload.port = 35729;
     middleware.push(liveReload({port: o.livereload.port}));
     util.log(util.colors.green('Connect LiveReload on ' + o.livereload.port + ' port'));
   }
   o.root.forEach(function (path) {
     middleware.push(connect.static(path));
   });
   var app = connect.apply(null, middleware);
   var server = http.createServer(app);
   if (o.root.length) app.use(connect.directory(o.root[0]));
   server
     .listen(o.port)
     .on('listening', function () {
       if (o.livereload) {
         lr = tiny_lr();
         lr.listen(o.livereload.port);
       }
       var url, browsername;
       util.log(util.colors.green('Server started on ' + o.port + ' port'));
       if (o.open) {
         url = 'http://localhost:' + o.port + '/' + o.open.file;
         if (o.open.browser) browsername = o.open.browser;
         else browsername = 'default browser';
         open(url, o.open.browser, function (error) {
           if (error) util.log(util.colors.red(error));
           else util.log(util.colors.green('Opened ' + url + ' in ' + browsername));
         });
       }
     })
 };
 middleware: (server) => {
     return [
         connectLivereload({
             port: CONSTS.LIVERELOAD_PORT
         })
     ];
 }
Example #13
0
  start: function(options) {
    var ui      = this.ui;
    var watcher = this.watcher;
    var middleware = chain();
    var app = this.app = express();

    if (options.liveReload === true) {
      middleware = chain(middleware, livereloadMiddleware({
        port: options.liveReloadPort
      }));
    }

    middleware = chain(middleware, serveFilesMiddleware({
      watcher: watcher,
      baseURL: options.baseURL
    }));

    if (options.proxy) {
      var urlopts = url.parse(options.proxy);

      ui.write('Proxying to ' + options.proxy + '\n');
      middleware = chain(middleware, proxy(urlopts));
    }

    this.processAddonMiddlewares(options);
    this.processAppMiddlewares();

    app.use(middleware);

    this.setupHttpServer();
    return this.listen(options.port, options.host)
      .then(function() {
        ui.write('Serving on http://' + options.host + ':' + options.port + '\n');
      });
  }
Example #14
0
gulp.task('serve', function() {
  express()
    .use(!build ? connectLr() : function(){})
    .use(express.static(targetDir))
    .listen(port);
  open('http://localhost:' + port + '/');
});
Example #15
0
/**
 * Initialization
 */
function initialize(port, alias, base) {

    initDB();

    app.set('port', process.env.PORT || port);
    app.set('base', base);
    app.set('alias', alias);

    app.use(alias, favicon());
    app.use(alias, cookieParser());
    app.use(alias, compress());                         // Compression
    app.use(alias, express.static(app.get('base')));    // Set the static files location
    app.use(alias, bodyParser.json());                  // To support JSON-encoded bodies

    /*
     * Much of the Passport docs center around sessions.
     *
     * We are not using sessions here. We are doing token based auth instead of
     * sessions and cookies.
     *
     * Because of this, flash messages will not work.
     */
    app.use(alias, passport.initialize());

    app.use(alias, livereload());

    setRoutes();
    setAuthStrategy();
}
Example #16
0
(function(){

  'use strict';
  var express = require('express');
  var reloader = require('connect-livereload')
  var app = express();


var body = ''
process.stdin.on('data', function(chunk){
  body += chunk
})

process.stdin.on('end', function(){
  console.log('body');
  console.log(body);
})

  app.use(reloader());
  app.use(express.static('./client'));


  app.listen(9000, function(){
    console.log('App Listening on localhost:9000');
  });

})();
Example #17
0
  start: function(options) {
    var ui      = this.ui;
    var project = this.project;
    var watcher = this.watcher;
    var middleware = chain();

    if (options.liveReload === true) {
      middleware = chain(middleware, livereloadMiddleware({
        port: options.liveReloadPort
      }));
    }

    middleware = chain(middleware, serveFilesMiddleware({
      watcher: watcher,
      baseURL: options.baseURL
    }));

    if (options.proxy) {
      var urlopts = url.parse(options.proxy);

      ui.write('Proxying to ' + options.proxy + '\n');
      middleware = chain(middleware, proxy(urlopts));
    }

    var server = project.require('./server')(middleware);
    var listen = Promise.denodeify(server.listen.bind(server));

    return listen(options.port, options.host)
      .then(function() {
        ui.write('Serving on http://' + options.host + ':' + options.port + '\n');
      });
  }
Example #18
0
    $.gulp.task('webserver', () => {
        const connect = require('connect-livereload')
        const express = require('express')
        const open = require('open')
        const request = require('request')

        const app = express()

        const PORT = $.config.port
        const PORT_RELOAD = 35729

        // ROUTES
        app
        .use(connect({port: PORT_RELOAD}))
        .use(express.static($.deploy.dir))
        .use('/*', (req, res) => res.sendFile($.path.resolve(__dirname, `../../${$.deploy.dir}`)))
        .use('/api', (req, res) =>
            req
            .pipe(request(`http://api${req.path}`))
            .pipe(res)
        )
        .listen(PORT, () => console.log('Listening on port %d', PORT))

        // LIVERELOAD
        $.tinylr.listen(PORT_RELOAD, () => console.log('Listening on port %d', PORT_RELOAD))

        // LAUNCH
        open(`http://localhost:${PORT}`)
    })
gulp.task('run', ['compile-font', 'watch-html', 'watch-js', 'watch-scss', 'watch-test-js'], () => {
  let logPrefix = '[' + util.colors.blue('run') + ']';

  let proxyPort = argv['proxy-port'] || process.env['GULP_PROXY_PORT'] || 4444;
  let expressPort = argv['express-port'] || process.env['GULP_EXPRESS_PORT'] || 7777;
  let liveReloadPort = argv['live-reload-port'] || process.env['GULP_LIVE_RELOAD_PORT'] || 35729;

  liveReload.listen(liveReloadPort);

  proxy(logPrefix, proxyOptions(expressPort), proxyPort);

  return express()
    .use(morgan('combined'))
    .use('/css', expressStatic('target/gulp/main/css'))
    .use('/fonts', expressStatic('target/gulp/main/fonts'))
    .use('/html', expressStatic('src/main/webapp/html'))
    .use('/img', expressStatic('src/main/webapp/img'))
    .use('/js', expressStatic('target/gulp/main/js'))
    .use(connectLiveReload({
      port: liveReloadPort
    }))
    .use('/test/js', expressStatic('target/gulp/test/js'))
    .use('/test', expressJasmine())
    .use('/specs', expressStatic('src/test/webapp/specs'))
    .use(expressIndex())
    .listen(expressPort, function () {
      util.log(logPrefix, 'Express listening on port', util.colors.green(expressPort));
    });
});
Example #20
0
function serveSPA() {
    var server = express();
    tinylr.listen(config_1.LIVE_RELOAD_PORT);
    server.use(config_1.APP_BASE, connectLivereload({ port: config_1.LIVE_RELOAD_PORT }), express.static(process.cwd()));
    server.listen(config_1.PORT, function () {
        return openResource('http://localhost:' + config_1.PORT + config_1.APP_BASE + config_1.APP_DEST);
    });
}
Example #21
0
 middleware: function (connect) {
     return [
         modRewrite(['^((?!\\.css|\\.js|\\.html|\\.eot|\\.svg|\\.ttf|\\.woff|\\.png|\\.jpg|\\.gif|\\.pdf|\\.jpeg).)*$ /index.html [L]']),
         livereload({port: 35730}),
         connect.static(path.resolve('.tmp')),
         connect.static(path.resolve('./'))
     ];
 }
Example #22
0
gulp.task('serve', ['sass', 'browserify'], function () {
	var app = express();
	app.use(connectLivereload({
		port: livereloadPort
	}));
	app.use(require('./src/app')());
	app.listen(serverPort);
});
Example #23
0
function startExpress() {

  var app = express();

  app.use(CLR());
  app.use(express.static(EXPRESS_ROOT));
  app.listen(EXPRESS_PORT);
}
Example #24
0
gulp.task('serve', function() {
  express()
    .use(connectLr())
    .use(express.static(paths.dist.path))
    .listen('3100')

  open('http://localhost:' + 3100 + '/')
})
Example #25
0
gulp.task('serve', ['sass'], function () {
	var server = express();
	server.use(connectLivereload({
		port: livereloadPort
	}));
	server.use(express.static('.'));
	server.listen(serverPort);
});
Example #26
0
 return new Promise(function (resolve, reject) {
   CONNECT_APP = connect()
     .use('/', http_request_handler)
     .use(connectLiveReload({
       port: LIVE_RELOAD_PORT
     }));
   resolve(CONNECT_APP);
 });
Example #27
0
], function() {
    
    var compiler = webpack(webpackCfg);

    var webpackDevMiddlewareInstance = webpackDevMiddleware(compiler, {
        publicPath: '/dist',
        aggregateTimeout: 300, // wait so long for more changes
        poll: true, // use polling instead of native watchers
        stats: {
            chunks: true
        }
    });
    var app = express();
    app.use(function(req, res, next) {
        // 支持 CORS 跨域
        res.setHeader('Access-Control-Allow-Origin', '*');
        next();
    });
    app.use(webpackDevMiddlewareInstance);
    
    app.use(livereload({
        port: 35729
    })); 
    app.use(serveStatic('.'));

    compiler.plugin('done', function(stats) {
        console.log(colors.info('###### pack_demo done ######'));
        lrServer.changed({body: {files: ['.']}});
    })

    webpackDevMiddlewareInstance.waitUntilValid(function(){
      console.log(colors.info('Package is in a valid state'));
      open(url)
    });

    // 开启 livereload

    lrServer.listen(35729, function() {
        console.log(colors.info('livereload server start: listening on 35729'));
    });

    // 开启调试服务
    portscanner.findAPortNotInUse(3000, 3010, ip.address(), function(error, port) {
        url = "http://" + ip.address() + ":" + port;
        var server = app.listen(port, function(err) {
            console.log(colors.info("dev server start: listening at " + url));
            if (err) {
                console.error(err);
            }
        });
        ;
    })
    
    gulp.watch(path.join(process.cwd(), './src/**/*.less'), ['reload_by_demo_css']);

    gulp.watch(path.join(process.cwd(), './demo/**/*.less'), ['reload_by_demo_css']);

});
Example #28
0
 middleware: function (connect, options) {
   var optBase = (typeof options.base === 'string') ? [options.base] : options.base;
   return [
     liveReload(), // Required until this bug is fixed
                   // https://github.com/AveVlad/gulp-connect/pull/83
     modRewrite(['!(\\..+)$ /example/ [L]'])
   ].concat(
     optBase.map(function(path){ return connect.static(path); }));
 }
Example #29
0
gulp.task('express', function() {
  var app = express();
  app.use(connectlivereload({ port: 35729 }));
  app.use(express.static('./dist'));
  var port = 4000;
  app.listen(port, '0.0.0.0', function(){
    console.log('App running and listening on port', port);
  });
});
Example #30
0
gulp.task('server', function() {
  var server = connect();

  server.use(connectLivereload({ port: lrPort }));
  server.use(connect.static(path['public']));
  server.listen(localPort);

  console.log("\nlocal server running at http://localhost:" + localPort + "/\n");
});