Skip to content

Commit

Permalink
[wip] More SS options
Browse files Browse the repository at this point in the history
  • Loading branch information
shakyShane committed Sep 29, 2016
1 parent c1bfc5c commit cc2f4d9
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 24 deletions.
4 changes: 0 additions & 4 deletions lib/async-tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ module.exports = [
step: "Starting the Server",
fn: async.startServer
},
{
step: "Adding serve static middlewares",
fn: async.addServeStaticMiddleware
},
{
step: "Starting the HTTPS Tunnel",
fn: async.startTunnel
Expand Down
12 changes: 0 additions & 12 deletions lib/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,18 +246,6 @@ module.exports = {
}
});
},
/**
* @param bs
* @param done
*/
addServeStaticMiddleware: function (bs, done) {
bs.options
.get("serveStatic")
.forEach(function (dir) {
bs.addMiddleware("*", utils.serveStatic(dir));
});
done();
},
/**
* @param {BrowserSync} bs
* @param {Function} done
Expand Down
2 changes: 1 addition & 1 deletion lib/browser-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ BrowserSync.prototype.doFileReload = function (data) {

/**
* If the current item will cause the browser
* to reload, fire the correct
* to reload, fire the correct
*/
if (willReload) {
bs.io.sockets.emit("browser:reload");
Expand Down
43 changes: 36 additions & 7 deletions lib/server/utils.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
"use strict";

var fs = require("fs");
var filePath = require("path");
var connect = require("connect");
var http = require("http");
var https = require("https");
var Map = require("immutable").Map;
var snippet = require("./../snippet").utils;
var fs = require("fs");
var filePath = require("path");
var connect = require("connect");
var Immutable = require("immutable");
var http = require("http");
var https = require("https");
var Map = require("immutable").Map;
var snippet = require("./../snippet").utils;
var _ = require("./../../lodash.custom");
var serveStatic = require("serve-static");

var utils = {
/**
Expand Down Expand Up @@ -79,6 +82,32 @@ var utils = {
})
}

if (options.get('serveStatic')) {
options
.get("serveStatic")
.forEach(function (dir, i) {
if (Immutable.Map.isMap(dir)) {
var ssOptions = (function () {
if (dir.get('options')) {
return dir.get('options').toJS();
}
return {}
})();
defaultMiddlewares.push({
id: "Serve static " + i,
route: dir.get("route"),
handle: serveStatic(dir.get("dir"), ssOptions)
});
} else if (_.isString(dir)) {
defaultMiddlewares.push({
id: "Serve static " + i,
route: "",
handle: serveStatic(dir, options.get('serveStaticOptions').toJS())
});
}
});
}

/**
* Add the proxy Middleware to the end of the stack
*/
Expand Down

0 comments on commit cc2f4d9

Please sign in to comment.