Skip to content

Commit

Permalink
feat(serve-static): Added option serveStatic to allow proxy/snippet…
Browse files Browse the repository at this point in the history
… mode to easily serve local files
  • Loading branch information
shakyShane committed Jul 19, 2015
1 parent ec57fcf commit 0e60a7c
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/async-tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ 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: 12 additions & 0 deletions lib/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,18 @@ 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
6 changes: 6 additions & 0 deletions lib/default-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ module.exports = {

middleware: false,

/**
* Add additional directories from which static
* files should be served.
*/
serveStatic: [],

/**
* Enable https for localhost development. **Note** - this is not needed for proxy
* option as it will be inferred from your target url.
Expand Down
36 changes: 36 additions & 0 deletions test/specs/e2e/e2e.options.serveStatic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"use strict";

var browserSync = require("../../../index");

var request = require("supertest");
var assert = require("chai").assert;
var page = require("fs").readFileSync("test/fixtures/index.html", "utf-8");

describe("E2E `serveStatic` option", function () {

var bs;

before(function (done) {
browserSync.reset();
var config = {
logLevel: "silent",
online: false,
serveStatic: ["test/fixtures"]
};
bs = browserSync(config, done).instance;
});

after(function () {
bs.cleanup();
});

it("can serve static files regardless of running mode", function (done) {
request(bs.server)
.get("/index.html")
.expect(200)
.end(function (err, res) {
assert.equal(res.text, page);
done();
});
});
});

0 comments on commit 0e60a7c

Please sign in to comment.