From 8f20e5228458a4b9c573a985a69ff447d281b605 Mon Sep 17 00:00:00 2001 From: Justin Chase Date: Wed, 16 Dec 2015 13:23:37 -0600 Subject: [PATCH] Changed all files to have unix line endings --- examples/multiple/dist/dist.html | 18 +- src/index.coffee | 262 +++++++++++++-------------- test/test.js | 302 +++++++++++++++---------------- 3 files changed, 291 insertions(+), 291 deletions(-) diff --git a/examples/multiple/dist/dist.html b/examples/multiple/dist/dist.html index f5a8494..d5fa979 100644 --- a/examples/multiple/dist/dist.html +++ b/examples/multiple/dist/dist.html @@ -1,10 +1,10 @@ - - - - - Dist path - - -

Dist path

- + + + + + Dist path + + +

Dist path

+ \ No newline at end of file diff --git a/src/index.coffee b/src/index.coffee index 54deca0..a02e521 100644 --- a/src/index.coffee +++ b/src/index.coffee @@ -1,131 +1,131 @@ -path = require("path") -es = require("event-stream") -util = require("gulp-util") -http = require("http") -https = require("https") -fs = require("fs") -connect = require("connect") -liveReload = require("connect-livereload") -tiny_lr = require("tiny-lr") -opt = {} -server = undefined -lr = undefined - -class ConnectApp - constructor: (options) -> - opt = options - opt.port = opt.port || "8080" - opt.root = opt.root || path.dirname(module.parent.id) - opt.host = opt.host || "localhost" - opt.debug = opt.debug || false - @oldMethod("open") if opt.open - @server() - - server: -> - app = connect() - @middleware().forEach (middleware) -> - if typeof (middleware) is "object" - app.use middleware[0], middleware[1] - else - app.use middleware - if opt.https? - server = https.createServer - key: opt.https.key || fs.readFileSync __dirname + '/certs/server.key' - cert: opt.https.cert || fs.readFileSync __dirname + '/certs/server.crt' - ca: opt.https.ca || fs.readFileSync __dirname + '/certs/ca.crt' - passphrase: opt.https.passphrase || 'gulp' - app - else - server = http.createServer app - app.use connect.directory(if typeof opt.root == "object" then opt.root[0] else opt.root) - server.listen opt.port, (err) => - if err - @log "Error on starting server: #{err}" - else - @log "Server started http#{if opt.https? then 's' else ''}://#{opt.host}:#{opt.port}" - - stoped = false; - sockets = []; - - server.on 'close', => - if (!stoped) - stoped = true - @log "Server stopped" - - # Log connections and request in debug - server.on "connection", (socket) => - sockets.push socket - socket.on "close", => - sockets.splice sockets.indexOf(socket), 1 - - server.on "request", (request, response) => - @logDebug "Received request #{request.method} #{request.url}" - - stopServer = => - if (!stoped) - sockets.forEach (socket) => - socket.destroy() - - server.close() - process.nextTick( -> - process.exit(0); - ) - - process.on("SIGINT", stopServer); - process.on("exit", stopServer); - - if opt.livereload - tiny_lr.Server::error = -> - if opt.https? - lr = tiny_lr - key: opt.https.key || fs.readFileSync __dirname + '/certs/server.key' - cert: opt.https.cert || fs.readFileSync __dirname + '/certs/server.crt' - else - lr = tiny_lr() - lr.listen opt.livereload.port - @log "LiveReload started on port #{opt.livereload.port}" - - middleware: -> - middleware = if opt.middleware then opt.middleware.call(this, connect, opt) else [] - if opt.livereload - opt.livereload = {} if typeof opt.livereload is "boolean" - opt.livereload.port = 35729 unless opt.livereload.port - middleware.push liveReload(port: opt.livereload.port) - if typeof opt.root == "object" - opt.root.forEach (path) -> - middleware.push connect.static(path) - else - middleware.push connect.static(opt.root) - if opt.fallback - middleware.push (req, res) -> - require('fs').createReadStream(opt.fallback).pipe(res); - - return middleware - - log: (@text) -> - if !opt.silent - util.log util.colors.green(@text) - - logWarning: (@text) -> - if !opt.silent - util.log util.colors.yellow(@text) - - logDebug: (@text) -> - if opt.debug - util.log util.colors.blue(@text) - - oldMethod: (type) -> - text = 'does not work in gulp-connect v 2.*. Please read "readme" https://github.com/AveVlad/gulp-connect' - switch type - when "open" then @logWarning("Option open #{text}") - -module.exports = - server: (options = {}) -> new ConnectApp(options) - reload: -> - es.map (file, callback) -> - if opt.livereload and typeof lr == "object" - lr.changed body: - files: file.path - callback null, file - lr: lr - serverClose: -> do server.close +path = require("path") +es = require("event-stream") +util = require("gulp-util") +http = require("http") +https = require("https") +fs = require("fs") +connect = require("connect") +liveReload = require("connect-livereload") +tiny_lr = require("tiny-lr") +opt = {} +server = undefined +lr = undefined + +class ConnectApp + constructor: (options) -> + opt = options + opt.port = opt.port || "8080" + opt.root = opt.root || path.dirname(module.parent.id) + opt.host = opt.host || "localhost" + opt.debug = opt.debug || false + @oldMethod("open") if opt.open + @server() + + server: -> + app = connect() + @middleware().forEach (middleware) -> + if typeof (middleware) is "object" + app.use middleware[0], middleware[1] + else + app.use middleware + if opt.https? + server = https.createServer + key: opt.https.key || fs.readFileSync __dirname + '/certs/server.key' + cert: opt.https.cert || fs.readFileSync __dirname + '/certs/server.crt' + ca: opt.https.ca || fs.readFileSync __dirname + '/certs/ca.crt' + passphrase: opt.https.passphrase || 'gulp' + app + else + server = http.createServer app + app.use connect.directory(if typeof opt.root == "object" then opt.root[0] else opt.root) + server.listen opt.port, (err) => + if err + @log "Error on starting server: #{err}" + else + @log "Server started http#{if opt.https? then 's' else ''}://#{opt.host}:#{opt.port}" + + stoped = false; + sockets = []; + + server.on 'close', => + if (!stoped) + stoped = true + @log "Server stopped" + + # Log connections and request in debug + server.on "connection", (socket) => + sockets.push socket + socket.on "close", => + sockets.splice sockets.indexOf(socket), 1 + + server.on "request", (request, response) => + @logDebug "Received request #{request.method} #{request.url}" + + stopServer = => + if (!stoped) + sockets.forEach (socket) => + socket.destroy() + + server.close() + process.nextTick( -> + process.exit(0); + ) + + process.on("SIGINT", stopServer); + process.on("exit", stopServer); + + if opt.livereload + tiny_lr.Server::error = -> + if opt.https? + lr = tiny_lr + key: opt.https.key || fs.readFileSync __dirname + '/certs/server.key' + cert: opt.https.cert || fs.readFileSync __dirname + '/certs/server.crt' + else + lr = tiny_lr() + lr.listen opt.livereload.port + @log "LiveReload started on port #{opt.livereload.port}" + + middleware: -> + middleware = if opt.middleware then opt.middleware.call(this, connect, opt) else [] + if opt.livereload + opt.livereload = {} if typeof opt.livereload is "boolean" + opt.livereload.port = 35729 unless opt.livereload.port + middleware.push liveReload(port: opt.livereload.port) + if typeof opt.root == "object" + opt.root.forEach (path) -> + middleware.push connect.static(path) + else + middleware.push connect.static(opt.root) + if opt.fallback + middleware.push (req, res) -> + require('fs').createReadStream(opt.fallback).pipe(res); + + return middleware + + log: (@text) -> + if !opt.silent + util.log util.colors.green(@text) + + logWarning: (@text) -> + if !opt.silent + util.log util.colors.yellow(@text) + + logDebug: (@text) -> + if opt.debug + util.log util.colors.blue(@text) + + oldMethod: (type) -> + text = 'does not work in gulp-connect v 2.*. Please read "readme" https://github.com/AveVlad/gulp-connect' + switch type + when "open" then @logWarning("Option open #{text}") + +module.exports = + server: (options = {}) -> new ConnectApp(options) + reload: -> + es.map (file, callback) -> + if opt.livereload and typeof lr == "object" + lr.changed body: + files: file.path + callback null, file + lr: lr + serverClose: -> do server.close diff --git a/test/test.js b/test/test.js index daf07c1..a39910e 100644 --- a/test/test.js +++ b/test/test.js @@ -1,151 +1,151 @@ -var request = require('supertest'); -var connect = require('../index'); -require('mocha'); - - -describe('gulp-connect', function () { - it('Simple', function (done) { - connect.server(); - request('http://localhost:8080') - .get('/fixtures/simplest/test.txt') - .expect(/Hello world/) - .expect(200) - .end(function (err, res) { - connect.serverClose(); - if (err) return done(err); - done() - }); - }) - it('Root string', function (done) { - connect.server({ - root: __dirname + "/fixtures" - }); - request('http://localhost:8080') - .get('/multiple/app/index.html') - .expect(/app test/) - .end(function (err, res) { - connect.serverClose(); - if (err) return done(err); - done() - }); - }) - it('Root array', function (done) { - connect.server({ - root: [__dirname + "/fixtures/multiple/app", __dirname + "/fixtures/multiple/dist"] - }); - request('http://localhost:8080') - .get('/index.html') - .expect(/app test/) - .expect(200) - .end(function (err) { - if (err) return done(err); - }); - request('http://localhost:8080') - .get('/dist.html') - .expect(/dist test/) - .expect(200) - .end(function (err) { - connect.serverClose(); - if (err) return done(err); - done() - }); - }) - it('Port test', function (done) { - connect.server({ - root: __dirname + "/fixtures/multiple/app", - port: 3333 - }); - request('http://localhost:3333') - .get('/index.html') - .expect(/app test/) - .end(function (err) { - connect.serverClose(); - if (err) return done(err); - done() - }); - }) - it('Https test', function (done) { - //suppress invalid self-signed ssl certificate error - process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0" - connect.server({ - root: __dirname + "/fixtures/multiple/app", - https: true - }); - request('https://localhost:8080') - .get('/index.html') - .expect(/app test/) - .end(function (err) { - connect.serverClose(); - if (err) return done(err); - done() - }); - }) - it('Livereload test', function (done) { - connect.server({ - livereload: true - }); - request('http://localhost:35729') - .get('/') - .expect('Content-Type', /json/) - .end(function (err) { - if (err) return done(err); - }); - request('http://localhost:35729') - .get('/livereload.js') - .expect(200) - .end(function (err) { - connect.serverClose(); - if (err) return done(err); - done(); - }); - }) - it('Livereload https test', function (done) { - connect.server({ - livereload: true, - https: true - }); - request('http://localhost:35729') - .get('/') - .expect('Content-Type', /json/) - .end(function (err) { - if (err) return done(err); - }); - request('http://localhost:35729') - .get('/livereload.js') - .expect(200) - .end(function (err) { - connect.serverClose(); - if (err) return done(err); - done(); - }); - }) - it('Livereload port', function (done) { - connect.server({ - livereload: { - port: 35000 - } - }); - request('http://localhost:35000') - .get('/') - .expect('Content-Type', /json/) - .end(function (err) { - connect.serverClose(); - if (err) return done(err); - done(); - }); - }) - it('Fallback test', function (done) { - connect.server({ - fallback: __dirname + '/fixtures/simplest/test.txt' - }); - request('http://localhost:8080') - .get('/not/existing/path') - .expect(/Hello world/) - .expect(200) - .end(function (err, res) { - connect.serverClose(); - if (err) return done(err); - done() - }); - }) -}) +var request = require('supertest'); +var connect = require('../index'); +require('mocha'); + + +describe('gulp-connect', function () { + it('Simple', function (done) { + connect.server(); + request('http://localhost:8080') + .get('/fixtures/simplest/test.txt') + .expect(/Hello world/) + .expect(200) + .end(function (err, res) { + connect.serverClose(); + if (err) return done(err); + done() + }); + }) + it('Root string', function (done) { + connect.server({ + root: __dirname + "/fixtures" + }); + request('http://localhost:8080') + .get('/multiple/app/index.html') + .expect(/app test/) + .end(function (err, res) { + connect.serverClose(); + if (err) return done(err); + done() + }); + }) + it('Root array', function (done) { + connect.server({ + root: [__dirname + "/fixtures/multiple/app", __dirname + "/fixtures/multiple/dist"] + }); + request('http://localhost:8080') + .get('/index.html') + .expect(/app test/) + .expect(200) + .end(function (err) { + if (err) return done(err); + }); + request('http://localhost:8080') + .get('/dist.html') + .expect(/dist test/) + .expect(200) + .end(function (err) { + connect.serverClose(); + if (err) return done(err); + done() + }); + }) + it('Port test', function (done) { + connect.server({ + root: __dirname + "/fixtures/multiple/app", + port: 3333 + }); + request('http://localhost:3333') + .get('/index.html') + .expect(/app test/) + .end(function (err) { + connect.serverClose(); + if (err) return done(err); + done() + }); + }) + it('Https test', function (done) { + //suppress invalid self-signed ssl certificate error + process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0" + connect.server({ + root: __dirname + "/fixtures/multiple/app", + https: true + }); + request('https://localhost:8080') + .get('/index.html') + .expect(/app test/) + .end(function (err) { + connect.serverClose(); + if (err) return done(err); + done() + }); + }) + it('Livereload test', function (done) { + connect.server({ + livereload: true + }); + request('http://localhost:35729') + .get('/') + .expect('Content-Type', /json/) + .end(function (err) { + if (err) return done(err); + }); + request('http://localhost:35729') + .get('/livereload.js') + .expect(200) + .end(function (err) { + connect.serverClose(); + if (err) return done(err); + done(); + }); + }) + it('Livereload https test', function (done) { + connect.server({ + livereload: true, + https: true + }); + request('http://localhost:35729') + .get('/') + .expect('Content-Type', /json/) + .end(function (err) { + if (err) return done(err); + }); + request('http://localhost:35729') + .get('/livereload.js') + .expect(200) + .end(function (err) { + connect.serverClose(); + if (err) return done(err); + done(); + }); + }) + it('Livereload port', function (done) { + connect.server({ + livereload: { + port: 35000 + } + }); + request('http://localhost:35000') + .get('/') + .expect('Content-Type', /json/) + .end(function (err) { + connect.serverClose(); + if (err) return done(err); + done(); + }); + }) + it('Fallback test', function (done) { + connect.server({ + fallback: __dirname + '/fixtures/simplest/test.txt' + }); + request('http://localhost:8080') + .get('/not/existing/path') + .expect(/Hello world/) + .expect(200) + .end(function (err, res) { + connect.serverClose(); + if (err) return done(err); + done() + }); + }) +})