Skip to content

Instantly share code, notes, and snippets.

@anthonyringoet
Created December 9, 2014 08:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anthonyringoet/ffa8d002abe18c961571 to your computer and use it in GitHub Desktop.
Save anthonyringoet/ffa8d002abe18c961571 to your computer and use it in GitHub Desktop.
Tiny static live reload server
var gulp = require('gulp');
var livereload = require('gulp-livereload')
var port = process.env.PORT || 4444;
gulp.task('server', function(next) {
var finalhandler = require('finalhandler');
var http = require('http');
var serveStatic = require('serve-static');
var serve = serveStatic(__dirname, {'index': ['index.html']});
var server = http.createServer(function(req, res){
var done = finalhandler(req, res);
serve(req, res, done);
});
server.listen(port, next);
console.log("Static server running on: " + port);
});
gulp.task('watch', ['server'], function() {
var server = livereload();
gulp.watch('./**').on('change', function(file) {
server.changed(file.path);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment