Coder Social home page Coder Social logo

gulp-live-server's Introduction

gulp-live-server

status downloads tag license

A handy, light-weight server you're going to love.

Install

NPM

Usage

  • Serve a static folder(gls.script<'scripts/static.js'> is used as server script)

      var gulp = require('gulp');
      var gls = require('gulp-live-server');
      gulp.task('serve', function() {
        //1. serve with default settings
        var server = gls.static(); //equals to gls.static('public', 3000);
        server.start();
    
        //2. serve at custom port
        var server = gls.static('dist', 8888);
        server.start();
    
        //3. serve multi folders
        var server = gls.static(['dist', '.tmp']);
        server.start();
    
        //use gulp.watch to trigger server actions(notify, start or stop)
        gulp.watch(['static/**/*.css', 'static/**/*.html'], function (file) {
          server.notify.apply(server, [file]);
        });
      });
  • Serve with your own script file

      gulp.task('serve', function() {
        //1. run your script as a server
        var server = gls.new('myapp.js');
        server.start();
    
        //2. run script with cwd args, e.g. the harmony flag
        var server = gls.new(['--harmony', 'myapp.js']);
        //this will achieve `node --harmony myapp.js`
        //you can access cwd args in `myapp.js` via `process.argv`
        server.start();
    
        //use gulp.watch to trigger server actions(notify, start or stop)
        gulp.watch(['static/**/*.css', 'static/**/*.html'], function (file) {
          server.notify.apply(server, [file]);
        });
        gulp.watch('myapp.js', server.start.bind(server)); //restart my server
        
        // Note: try wrapping in a function if getting an error like `TypeError: Bad argument at TypeError (native) at ChildProcess.spawn`
        gulp.watch('myapp.js', function() {
          server.start.bind(server)()
        });
      });
  • Customized serving with gls

      gulp.task('serve', function() {
        //1. gls is the base for `static` and `new`
        var server = gls([gls.script, 'static', 8000]);
        //equals gls.new([gls.script, 'static', 8000]);
        //equals gls.static('static', 8000);
        server.start();
    
        //2. set running options for the server, e.g. NODE_ENV
        var server = gls('myapp.js', {env: {NODE_ENV: 'development'}});
        server.start();
    
        //3. customize livereload server, e.g. port number
        var server = gls('myapp.js', undefined, 12345);
        var promise = server.start();
        //optionally handle the server process exiting
        promise.then(function(result) {
          //log, exit, re-start, etc...
        });
    
        //4. start with coffee-script executable e.g. installed with npm
        var server = gls('myapp.coffee');
        server.start('node_modules/coffee-script/bin/coffee');
    
        //use gulp.watch to trigger server actions(notify, start or stop)
        gulp.watch(['static/**/*.css', 'static/**/*.html'], function (file) {
          server.notify.apply(server, [file]);
        });
        gulp.watch('myapp.js', server.start.bind(server)); //restart my server
        
        // Note: try wrapping in a function if getting an error like `TypeError: Bad argument at TypeError (native) at ChildProcess.spawn`
        gulp.watch('myapp.js', function() {
          server.start.bind(server)()
        });
      });

API

static([folder][, port])

  • folder - String|Array The folder(s) to serve. Use array of strings if there're multi folders to serve. If omitted, defaults to public/.
  • port - Number The port to listen on. Defaults to 3000.
  • return gls.

Config new server using the default server script, to serve the given folder on the specified port.

new(script)

  • script - String The script file to run.
  • return gls.

Config new server using the given script.

gls(args[, options][, livereload])

  • args - String|Array The 2nd param for ChildProcess.spawn.

  • options - Object The 3rd param for ChildProcess.spawn, will be mixin into the default value:

        options = {
            cwd: undefined
        }
        options.env = process.env;
        options.env.NODE_ENV = 'development';
  • livereload - Boolean|Number|Object The option for tiny-lr server. The default value is 35729.

    • false - will disable tiny-lr livereload server.
    • number - treated as port number of livereload server.
    • object - used to create tiny-lr server new tinylr.Server(livereload);

gls here is a reference of var gls = require('gulp-live-server'). It aims to assemble configuration for the server child process as well as the tiny-lr server. static and new are just shortcuts for this. Usually, static and new will serve you well, but you can get more customized server with gls.

start([execPath])

  • execPath - String The executable that is used to start the server. If none is given the current node executable is used.
  • return promise from Q, resolved with the server process exits.

Spawn a new child process based on the configuration.

stop()

Stop the server.

notify([event])

  • event - Event Event object passed along with gulp.watch. Optional when used with pipe.

Tell livereload.js to reload the changed resource(s)

livereload.js

gulp-live-server comes with tiny-lr built in, which works as a livereload server. livereload.js is served by tiny-lr, but in order to get it loaded with your page, you have 3 options( to inject <script src="//localhost:35729/livereload.js"></script> into your page):

Usually, if http://localhost:35729/livereload.js is accessible, then your livereload server is ok, if you don't have the script tag for livereload.js in you page, you've problem with either your chrome plugin or the connect-livereload middle-ware as mentioned above.

DEBUG

If you want more output, set the DEBUG environment variables to * or gulp-live-server.

gulp-live-server's People

Contributors

ahmader avatar aramk avatar bruno-c avatar ccapndave avatar dominikkukacka avatar douglas-vaz avatar geoffreyplitt avatar gimm avatar gingi avatar littlehelicase avatar llaraujo avatar lukejacksonn avatar m19c avatar nyakto avatar poke avatar r-murphy avatar simeg avatar tmont avatar x-cray avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

gulp-live-server's Issues

Using this with webpack dev-server

0.0.14 is the last working version when combining with webpack dev-server.
Newer versions fail with message:
gulp-live-server/index.js:201 this.lr.changed({body: {files: [filepath]}}); TypeError: Cannot read property 'lr' of undefined

Restart service documentation didn't work

Attempting to restart a process via the documentation in the README doesn't seem to work as expected (watch function gets called, but process doesn't get restarted). Instead I discovered that the below works well. Not sure if the documentation is off, or I'm doing something wrong, so I wanted to open a issue before a PR.

node: v10.1.0

The one that worked in restarting the process was:

gulp.task('serve', function () {
    var server = gls('app/app.js');
    server.start();

    gulp.watch('app/**/*', function (file) {
      console.log('reloading..');

      // doesnt work - comes from doc
      // server.notify.apply(server, [file]);

      // works
      server.start.bind(server)();
    });

    // unnecessary since file matches above watch glob
    // gulp.watch('app/app.js', server.start.bind(server));
  });

Inactive server and error message

If the started server is inactive for a while, you get error message to console and the process stops. (yet the server is still open). Something to do with the live-reload..? (error points to connect)
events.js:85
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE
at exports._errnoException (util.js:746:11)
at Server._listen2 (net.js:1129:14)
at listen (net.js:1155:10)
at Server.listen (net.js:1240:5)
at Function.app.listen (/node_modules/gulp-live-server/node_modules/connect/lib/proto.js:188:24)
at Object. (/node_modules/gulp-live-server/scripts/static.js:16:5)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)

A quick googling says the Error: listen EADDRINUSE means the port is already taken by some other process? That can't be...

UnhandledPromiseRejectionWarning server.start() Gulp 4

I'm getting the following warning thrown when I start the server

(node:69565) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 3): Error: Request failed with status code 404

I'm just using a regular gulp function and I've tried returning the the method as shown here, using a then(success, error) approach or a .catch() and nothing seems to get rid o that warning :-(

gulp.task('default', function(){ var server = gls.new('bin/www', {env: {DEBUG:'*'}}); return server.start(); });

--harmony not working

I'm on Node 0.12.2 trying to use gls with --harmony

I have a Gulpfile with gls using the "--harmony" flag. I also use the "--harmony" flag when running gulp itself below.

const gulp = require('gulp')
const gls = require('gulp-live-server')

const server = gls.new(['--harmony', 'app.js'])

gulp.task('express', () => {
  server.start()
})

And an app.js:

const express = require('express')
const app = express()
app.use(express.static('frontend'))
const port = process.env.PORT || 3000
const server = app.listen(port, () => {
  const host = server.address().address
  const port = server.address().port
  console.log('App listening at http://localhost:' + port)
})

The app runs fine without Gulp, with --harmony:

$ node --harmony app.js 
App listening at http://localhost:3000

But fails with "[code => 9 | sig => null]" with gls:

DEBUG=* node --harmony ./node_modules/gulp/bin/gulp.js express
[22:36:43] Using gulpfile /vagrant/Gulpfile.js
[22:36:43] Starting 'express'...
  tinylr:server Configuring HTTP server +0ms
[22:36:43] Finished 'express' after 11 ms
livereload[tiny-lr] listening on 35729 ...
  gulp-live-server server process exited with [code => 9 | sig => null] +0ms

Please advise, thanks.

Server only restarts if I run gulp with `gulp default "default"` command

I have the following Gulpfile:

const server = gls.new([
  '--trace-deprecation', '--trace-sync-io', 'bin/www',
]);
gulp.task('start', () => {
  return server.start();
});

...

gulp.task('app', gulp.parallel('start', 'css', 'uglify', 'files'));

gulp.task('watch:start', () => {
  //gulp.watch(paths.app, gulp.series('start'), server.start); // restart my server
  gulp.watch(paths.app, gulp.series('start'), (file) => {
    server.notify.apply(server, [file]);
  });
});

...

gulp.task('watch', gulp.parallel('watch:start', 'watch:stylus', 'watch:css', 'watch:uglify', 'watch:files'));

gulp.task('default', gulp.parallel('app', 'watch'));

If I run gulp default, the server only restart one times only, at the first when I do any modifications for example in my app.js. Meanwhile, if I re-save multiple times my main.styl file, it will re-compile the minified CSS every single time, works as expected.

I had to run gulp default "default" to be responsive every server restart, but than I run every command two times, which I think is wasting.

I running Gulp 4 now, but it was the same with Gulp 3.

Wrong environment variable

The docs say you are setting the standard $NODE_ENV but the code is actually setting $server_ENV. Possible misfire on search-and-replace?

Pipe example

It crashes when I attempt to use it with .pipe as server.notify

It works when you use server.notify() it would be nice to document this.

Livereload not reloading

I seem to be having issues getting the server to restart upon changes. Here is my task...

gulp.task('serve', function () {
  var server = gls.new('bin/www');
  server.start();

  gulp.watch(['routes/**/*.js', 'views/**/*.jade'], function (args) {
    server.notify.apply(server, [args]);
  });
});

When I change something, nothing happens in the output nor does a refresh reflect the changes I've made. Am I missing anything?

stop server if gulp exits abnormally

Is there a straight forward way to stop the sever if gulp exits abnormally? I really don't mind the exceptions getting through and killing gulp in some cases, and I don't know that I'd do anything more than rethrow in most cases BUT, I'd love for my test server to get cleaned up on exit.

Colored stdout by my app is not shown

Using info() in serverLog() caused my node app logs to be un-colored.
If I use
{ stdio : 'inherit' }
Then I lose the console.warn colors as stderr will arrive to stdout. But I will see stdout colors.

To fix this, I used this option to overcome this issue.
{ stdio : ['pipe', 'inherit', 'pipe'] }

Now I see the colors as per my node app logs and also any warning will come to stderr and colored by serverError()

PS. I had to remove info() from the serverLog() function.

livereload.js is not detecting changes.

I have an file called app.js which uses express.js to serve some content on port 3000. I have manually added livereload.js to the html and the LiveReload object is available in browser console.
This gulpfile reloads the app.js to restart the server but the page in the browser stays the same.

const gulp = require('gulp')
const gls = require('gulp-live-server')

const server = gls('app.js', undefined, 12345)

function restartExpress(cb) {
	server.start.bind(server)()
	server.notify.apply(server, [cb])
	cb()
}

exports.default = function () {
	server.start()
	gulp.watch(['./**/*', '!node_modules/**/*', '!db/**/*'], function (cb) {
		restartExpress(cb)
	})
}

Is the method correct or did I miss something?

Cannot set environment variables

hi, on version 0.0.7 i was able to set some environment variable before starting the server and it would work, but not now.

gulp.task('serve-dist', function () {
  process.env.NODE_ENV = 'production';
  g.liveServer(['./dist/server/app.js'], {}, false).start();
});

how can i handle this with the new version?

How to pass arguments from the command line to the 'app.js' file?

example:

$ gulp server --env development

var gulp = require('gulp');
var gls = require('gulp-live-server');
var gutil = require('gulp-util');

console.log(gutil.env.env);

gulp.task('server', function () {
  var server = gls.new('server/app.js');
  server.start();
});

Thanks for your time

Cannot read property changed

Hi,

I have problem with new version live-server v0.0.17, which me return this Error.

/node_modules/gulp-live-server/index.js:194
        exports.lr.changed({body: {files: [filepath]}});
                  ^
TypeError: Cannot read property 'changed' of undefined
  at Object.exports.notify (/node_modules/gulp-live-server/index.js:194:19)
  at [object Object]._onTimeout (gulpfile.js:347:17)
  at Timer.listOnTimeout (timers.js:110:15)

Where would be a problem? I use v0.0.14 and there was everything ok.

Thanks

Livereload port stays 35729 in default script when configured

I'm starting server like this gulfile.js:

gulp.task('serve', function() {
  var server = gls([gls.script, 'public', 9200], undefined, 9300);
  server.start();
  gulp.watch(['./dist/**/*.js', './public/**/*'], function (file) {
    server.notify.apply(server, [file]);
  });
});

Everything seems ok:

$ gulp serve
[14:26:54] Using gulpfile ~/work/tblib/trunk/web/tbjs/gulpfile.js
[14:26:54] Starting 'serve'...
[14:26:54] Finished 'serve' after 126 ms
livereload[tiny-lr] listening on 9300 ...
folder "public" serving at http://localhost:9200

But when I check the source:

<script>//<![CDATA[
document.write('<script src="//' + (location.hostname || 'localhost') + ':35729/livereload.js?snipver=1"><\/script>')
//]]></script>

I've tracked the problem - the livereload settings are not passed in ./scripts/static.js so livereload uses it's default port.

Add support for custom host

Currently, I can serve content on a custom port:

  let port = 1234;
  let server = gls.static(config.content, port);
  server.start();

It would be awesome if I could serve on a custom host too:

  let port = 1233;
  let host = '192.168.0.5';
  let server = gls.static(config.content, host, port);
  server.start();

Index.html in different folder than server

Hi all!

Is it possible to start a server at a specific location, and the index.html be in a different one?

var server = gls.static(`/`, port);
server.start('/dist/index.html'); // Just an idea

In the root folder, I have /dist, /src and /node_modules.
index.html is inside /src, which is copied to /dist.

I can't just start the server at /dist, because index.html depends on node_modules.

Thank you,
tbragaf

Delay due to files in current directory

Upon starting a server with gls('main.js').start(), I'm experiencing a delay due to the presence of my node_modules directory in the current directory. Moving the node_modules directory out of the way (for instance with mv node_modules ..) removes the delay.

I may be missing something obvious in the documentation, but is there a way to get rid of this delay? Is it perhaps possible (and meaningful) to instruct gulp-live-server to configure tiny-lr to serve another directory instead (or perhaps disable static file serving altogether)?

Thanks!

can not update code

I add this code in my gulpfile.js, and when the js file changed, I can get the console output. But the code did not update in my server.
gulp.watch(['service/*.js'], function(file) {
console.log(file)
server.notify.apply(server, [file]);
});

I can reach http://localhost:35729/livereload.js.

CPU usage

When I run gulp-live-server and I issue:

gulp.watch(['client/**/*.css','client/**/*.js', 'client/**/*.html'], function (file) { server.notify.apply(server, [file]); });

My CPU spikes to almost 100% when the browser reloads.

Live reload and https

Could you provide an example of how livereload is configured please as I can't get it to work for me.

I have the following to try and get an https application to use livereload but it fails as whatever i do the livereload option keeps getting overwritten by the default

var gls = require('gulp-live-server');

var livereload = {
key: fs.readFileSync('./config/key.pem'),
cert: fs.readFileSync('./config/cert.pem')
};

gulp.task('express', false, ['test'], function () {
// Start the server at the beginning of the task
var server = gls.new(paths.config + 'server.js');
server.start();
});

TypeError: Cannot read property 'lr' of null

I trust there's error in index.js on line 207

   return es.map(function(file, done) {
       var filepath = path.relative(__dirname, file.path);
       debug(info('file(s) changed: %s'), filepath);
>>>    this.lr.changed({body: {files: [filepath]}});
       done(null, file);
   });

because no context will be given by es.map

this error breaks usage case:

gulp.src('')
    .pipe(server.notify());

TypeError: Cannot read property 'lr' of undefined

gulp 3.8.11, gulp-live-server 0.0.20, node 0.10.25. I'm experiencing the following exception, which is raised at the first saving of a watched file:

> gulp serve
[17:33:19] Using gulpfile project/gulpfile.js
[17:33:19] Starting 'serve'...
[17:33:19] Finished 'serve' after 15 ms
livereload[tiny-lr] listening on 35729 ...
GET / 304 146.684 ms - -
GET /stylesheets/style.css 304 5.846 ms - -

project/node_modules/gulp-live-server/index.js:202
        this.lr.changed({body: {files: [filepath]}});
            ^
TypeError: Cannot read property 'lr' of undefined
    at exports.notify (project/node_modules/gulp-live-server/index.js:202:13)
    at Gaze.<anonymous> (project/node_modules/gulp/node_modules/vinyl-fs/node_modules/glob-watcher/index.js:18:14)
    at Gaze.EventEmitter.emit (events.js:98:17)
    at Gaze.emit (project/node_modules/gulp/node_modules/vinyl-fs/node_modules/glob-watcher/node_modules/gaze/lib/gaze.js:129:32)
    at project/node_modules/gulp/node_modules/vinyl-fs/node_modules/glob-watcher/node_modules/gaze/lib/gaze.js:415:16
    at StatWatcher._pollers.(anonymous function) (project/node_modules/gulp/node_modules/vinyl-fs/node_modules/glob-watcher/node_modules/gaze/lib/gaze.js:326:7)
    at StatWatcher.EventEmitter.emit (events.js:98:17)
    at StatWatcher._handle.onchange (fs.js:1109:10)

gulpfile.js:

var gulp = require('gulp');
var gls = require('gulp-live-server');

gulp.task('serve', function() {
  //1. run your script as a server
  var server = gls.new('bin/www');
  server.start();

  // use gulp.watch to trigger server actions(notify, start or stop)
  gulp.watch('views/**/*.jade', server.notify);
  gulp.watch('public/**/*', server.notify);
  // Event object won't pass down to gulp.watch's callback if there's more than one of them. 
  // So the correct way to use server.notify is as following: 
  // gulp.watch('public/stylesheets/**/*.less', function(event) {
  //   gulp.run('less');
  //   server.notify(event);
  // });
  gulp.watch(['.env', 'bin/www', 'app.js', 'routes/**/*.js'], function(event) {
    server.start()
    .then(function() {
      return setTimeout(function() {
        return server.notify(event);
      }, 1000);
    }).catch(function (error) {
      throw error;
    }).done();
  }); //restart my server
});

server.start() doesn't return a promise once server has started

From the code and from the behavior of calling server.start(), it looks like it only resolves if the server exits.

Maybe that was on purpose, but it seems that intuitively it would be called once the server has started successfully, not after the script file has run and then exited.

I would like to do something like this in my gulp file:

gulp.task('test-client', function (done) {

    var server = gls.new('server/index.js');

    server.start()
        .then(function () {
            karma.start({
                configFile: __dirname + '/spec/support/karma.conf.js',
                singleRun:  true
            }, function () {
                server.stop().then(done);
            });
        })
    ;

});

Where I can run my Karma tests once I know that the server has started successfully.

Would this be possible?

Be more clear with the default options documentation

In the documentation for the default settings it is not clear that it will serve files from the ./public directory.

//1. serve with default settings
var server = gls.static(); //equals to gls.static('public', 3000);
server.start();

Just add
//This will serve the files from the ./public directory

error on sample page

Hi

On your npm page you give a sample how to restart a server once the main js file changes:

gulp.watch('myapp.js', server.start.bind(server)); //restart my server 

This fails because the watch pipes the changed file to the start command.

What worked for me was:

gulp.watch('app.js', function(){server.start();}); //restart my server

Server.notify with gulp 4

I know it's still in beta, but gulp 4 will be the defacto gulp version soon. I have been able to get everything to work so far except server.notify.

when use gulp,restart error

gulpfile.js: gulp.watch('some.file.ext', server.start.bind(server));

gls/index.js:exports.start = function (execPath) {...this.server = spawn(this.config.execPath, this.config.args, this.config.options);...}

execPath will be:{type: evt, path: path}

come from glob-watched/index.js:

rwatcher.on('all', function(evt, path, old){
      var outEvt = {type: evt, path: path};
      if(old) outEvt.old = old;
      out.emit('change', outEvt);
      if(cb) cb(outEvt);
    });

then get the spawn error:

child_process.js:1136
  var err = this._handle.spawn(options);
                         ^
TypeError: Bad argument
    at TypeError (native)
    at ChildProcess.spawn (child_process.js:1136:26)
    at exports.spawn (child_process.js:995:9)
    at Object.exports.start (..\node_modules\gulp-live-server\index.js:134:19)
    at Gaze.<anonymous> (..\node_modules\gulp\node_modules\vinyl-fs\node_modules\glob-watcher\index.js:18:14)
    at Gaze.emit (events.js:110:17)
    at Gaze.emit (..\node_modules\gulp\node_modules\vinyl-fs\node_modules\glob-watcher\node_modules\gaze\lib\gaze.js:129:32)
    at ..\node_modules\gulp\node_modules\vinyl-fs\node_modules\glob-watcher\node_modules\gaze\lib\gaze.js:415:16
    at StatWatcher._pollers.(anonymous function) (..\node_modules\gulp\node_modules\vinyl-fs\node_modules\glob-watcher\node_modules\gaze\lib\gaze.js:32
    at StatWatcher.emit (events.js:110:17)

Custom content-type

I'm having some problems with firefox and .sea files, as the server doesn't set content-type for any files. Is there a way to assign it manually? Is middleware required?

Problems in windows with: "start": "gulp watch|node server.js"

I have this gulpfile.js

var gulp = require('gulp');
var sass = require('gulp-sass');
var rename = require('gulp-rename');
var babel = require('babelify');
var browserify = require('browserify');
var source = require('vinyl-source-stream');
var watchify = require('watchify');

gulp.task('styles', function () {
gulp
.src('index.scss')
.pipe(sass())
.pipe(rename('app.css'))
.pipe(gulp.dest('public'));
})

gulp.task('assets', function () {
gulp
.src('assets/*')
.pipe(gulp.dest('public'));
})

function compile(watch) {
var bundle = watchify(browserify('./lib/index.js'));

function rebundle() {
bundle
.transform(babel)
.bundle()
.pipe(source('index.js'))
.pipe(rename('app.js'))
.pipe(gulp.dest('public'));
}

if (watch) {
bundle.on('update', function (){
console.log('--> Bundling...');
rebundle();
})
}

rebundle();
}

gulp.task('build', function () { return compile(); });

gulp.task('watch', function (){ return compile(true); });

gulp.task('default',['styles', 'assets', 'build'])

so in console I should put: npm start
but or the gulp watch runs and thats it, or only the server.js works.

how do I need to set the package.json to make it work?
I have this:

"author": "KhanterWinters", "dependencies": { "empty-element": "^1.0.0", "express": "^4.14.0", "materialize-css": "^0.97.7", "page": "^1.7.1", "pug": "^2.0.0-beta6", "yo-yo": "^1.3.0" }, "devDependencies": { "babelify": "^7.3.0", "browserify": "^13.1.0", "gulp": "^3.9.1", "gulp-rename": "^1.2.2", "gulp-sass": "^2.3.2", "vinyl-source-stream": "^1.1.0", "watchify": "^3.7.0" }, "scripts": { "build": "gulp", "start": "gulp watch|node server.js" }

Running multiple servers in a single gulp script

I am trying to run gls twice - once to serve some static content, and once to start a restify server on another port. However, it looks like you can only run one at a time; starting one seems to close the other. Is this intended behaviour, and if so is there a way around it?

Livereload port problem

var server = gls('server.js', undefined, livereloadPort);
server.start();

You can control the livereload port number with this, but then you get error from the localhost:
GET http://localhost:35729/livereload.js?snipver=1 net::ERR_CONNECTION_REFUSED

The server.js file is same as in your examples. As a sidenote, app.use(require('connect-livereload')()); in the example server.js is not actually doing anything...not even if you pass a port-number to it like in the connect-livereload documentation. Anyway.

If you say in your instructions, that you can change the port number for livereload, i will expect that things just work. What do you think? If the external server.js file is used with changed livereload port, where the livereload script injection comes from?

server.start as watch callback not setting "this"

Using the examples provided, I am encountering the following bug.

When the "myapp.js" file changes, gulp triggers the "server.start" function in the callback. This produces:

if (this.server) { // server already running
            ^
TypeError: Cannot read property 'server' of undefined

On ln 115 "index.js". Fixed this by explicitely writing the callback as:

function () {
  server.start.apply(server);
}

Which is similar to how the application of notify method is written.

Cannot restart the server

I have this piece of code:

gulp.task('server', function () {
    var srv = gls.new('./bin/localhost');

    srv.start();

    gulp.watch('./bin/localhost', srv.start.bind(srv));
});

When I launch it the output is:

[16:42:33] Using gulpfile ~/Projects/myproject/gulpfile.js
[16:42:33] Starting 'server'...
[16:42:33] Finished 'server' after 8.77 ms
livereload[tiny-lr] listening on 35729 ...

But if I change the "bin/localhost" file I get this error:

child_process.js:923
  var r = this._handle.spawn(options);
                       ^
TypeError: Bad argument
    at ChildProcess.spawn (child_process.js:923:24)
    at exports.spawn (child_process.js:723:9)
    at Object.exports.start (/home/softomatix/Projects/myproject/node_modules/gulp-live-server/index.js:135:19)
    at Gaze.<anonymous> (/home/softomatix/Projects/myproject/node_modules/gulp/node_modules/vinyl-fs/node_modules/glob-watcher/index.js:18:14)
    at Gaze.EventEmitter.emit (events.js:98:17)
    at Gaze.emit (/home/softomatix/Projects/myproject/node_modules/gulp/node_modules/vinyl-fs/node_modules/glob-watcher/node_modules/gaze/lib/gaze.js:129:32)
    at /home/softomatix/Projects/myproject/node_modules/gulp/node_modules/vinyl-fs/node_modules/glob-watcher/node_modules/gaze/lib/gaze.js:415:16
    at StatWatcher._pollers.(anonymous function) (/home/softomatix/Projects/myproject/node_modules/gulp/node_modules/vinyl-fs/node_modules/glob-watcher/node_modules/gaze/lib/gaze.js:326:7)
    at StatWatcher.EventEmitter.emit (events.js:98:17)
    at StatWatcher._handle.onchange (fs.js:1109:10)

My small investigation showed that the first parameter of ChildProcess.spawn is an object:

{ type: 'changed',
  path: '/home/softomatix/Projects/foodbarn.js/bin/localhost' }

but according to method's documentation it is supposed to be a string:

https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options

Is that an issue?

Problem with engine

Hello,
I am trying to migrate my gulp express server to this package. My server uses twig as a default engine.

Is possible to set twig as a default view engine here?

Thanks for all.
Regards.

start() promise doesn't resolve?

Got a custom express server.js being run by gls.

gulp.task('server', function (callback) {

    var server = plugins.liveServer.new('server.js');

    // live reload changed resource(s).
    gulp.watch([ 'public/**/*' ], server.notify);

    // Restart if server.js itself is changed.
    gulp.watch('server.js', server.start);

    server.start().then(function () {
        console.log('************** started!');
        callback();
    });

});

How does the promise resolve? I was hoping it was when server.js logs to console (as other grunt/gulp plugins work) - I couldn't find any documentation about how that works?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.