Permalink
Browse files

can now pass in own http server

  • Loading branch information...
1 parent f670f58 commit b53e2c475cc5052fe7ac53e1160a26021f1c9afb @eugeneware eugeneware committed Jul 6, 2012
Showing with 21 additions and 3 deletions.
  1. +1 −1 lib/livereload.coffee
  2. +4 −2 lib/livereload.js
  3. +16 −0 test/index.test.coffee
@@ -109,7 +109,7 @@ exports.createServer = (config) ->
res.writeHead(200, {'Content-Type': 'text/javascript'})
res.end fs.readFileSync __dirname + '/../ext/livereload.js'
- config.server = app
+ config.server ?= app
server = new Server config
server.listen()
View
@@ -162,7 +162,7 @@
})();
exports.createServer = function(config) {
- var app, server;
+ var app, server, _ref;
app = http.createServer(function(req, res) {
if (url.parse(req.url).pathname === '/livereload.js') {
res.writeHead(200, {
@@ -171,7 +171,9 @@
return res.end(fs.readFileSync(__dirname + '/../ext/livereload.js'));
}
});
- config.server = app;
+ if ((_ref = config.server) == null) {
+ config.server = app;
+ }
server = new Server(config);
server.listen();
return server;
@@ -17,3 +17,19 @@ describe 'livereload http file servingt', ->
server.config.server.close()
done()
+ it 'should allow you to override the internal http server', (done) ->
+ app = http.createServer (req, res) ->
+ if url.parse(req.url).pathname is '/livereload.js'
+ res.writeHead(200, {'Content-Type': 'text/javascript'})
+ res.end '// nothing to see here'
+
+ server = livereload.createServer({port: 35729, server: app})
+
+ request 'http://localhost:35729/livereload.js?snipver=1', (error, response, body) ->
+ should.not.exist error
+ response.statusCode.should.equal 200
+ body.should.equal '// nothing to see here'
+
+ server.config.server.close()
+
+ done()

0 comments on commit b53e2c4

Please sign in to comment.