Skip to content

Commit

Permalink
fix(plugins): Allow plugins to register middleware via server:middlew…
Browse files Browse the repository at this point in the history
…are hook when in proxy mode - fixes #663
  • Loading branch information
shakyShane committed Jun 9, 2015
1 parent 864bdf0 commit 104dbb4
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/server/proxy-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ function getOptions (bs, scripts) {
* @returns {*}
*/
function getPluginMiddleware (bs, scripts) {
return bs.pluginManager.hook("server:middleware", snippetUtils.getProxyMiddleware(scripts, bs.options.getIn(["scriptPaths", "versioned"])));
return bs.pluginManager.hook("server:middleware", [
snippetUtils.getProxyMiddleware(scripts, bs.options.getIn(["scriptPaths", "versioned"]))
]);
}

/**
Expand Down
60 changes: 60 additions & 0 deletions test/specs/plugins/user.plugins.proxy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"use strict";

var browserSync = require("../../../");
var testUtils = require("../../protractor/utils");
var Immutable = require("immutable");
var sinon = require("sinon");
var request = require("supertest");

describe("Plugins: Should be able to register middleware when in proxy mode", function () {

var bs;
var app;
var spy;

before(function (done) {

browserSync.reset();

app = testUtils.getApp(Immutable.Map({scheme: "http"}));
app.server.listen();

spy = sinon.spy();

var config = {
proxy: "http://localhost:" + app.server.address().port,
open: false,
logLevel: "silent"
};

browserSync.use({
"plugin": function () {
/* noop */
},
"hooks": {
"server:middleware": function () {
return function (req, res, next) {
spy();
next();
};
}
},
"plugin:name": "KITTENZ"
});

bs = browserSync(config, done).instance;
});

after(function () {
bs.cleanup();
});
it("should serve the file", function (done) {
request(bs.server)
.get("/")
.set("accept", "text/html")
.end(function () {
sinon.assert.calledOnce(spy);
done();
});
});
});

0 comments on commit 104dbb4

Please sign in to comment.