Skip to content

Commit

Permalink
fix(client-script): allow proxy to also use client script middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane Osbourne committed Jun 17, 2015
1 parent dbe9ffe commit c5fdbbf
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 31 deletions.
2 changes: 1 addition & 1 deletion lib/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ module.exports = {
bs.pluginManager.get("client:script")(
bs.options.toJS(),
clientJs,
bs.options.get("proxy") ? "file" : "middleware"
"middleware"
)
);

Expand Down
21 changes: 5 additions & 16 deletions lib/server/proxy-server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"use strict";

var snippetUtils = require("./../snippet").utils;
var _ = require("lodash");
var utils = require("./utils");
var Immutable = require("immutable");
Expand All @@ -26,6 +25,9 @@ module.exports = function createProxyServer (bs, scripts) {

var proxy = utils.getServer(bs.proxy.app, bs.options);

bs.proxy.app.use(bs.options.getIn(["scriptPaths", "versioned"]), scripts);
bs.proxy.app.use(bs.options.getIn(["scriptPaths", "path"]), scripts);

/**
* How best to handle websockets going forward?
*/
Expand All @@ -36,9 +38,8 @@ module.exports = function createProxyServer (bs, scripts) {

/**
* @param bs
* @param scripts
*/
function getOptions (bs, scripts) {
function getOptions (bs) {

var options = bs.options;

Expand All @@ -50,7 +51,7 @@ function getOptions (bs, scripts) {
rules: rules.opts.rules,
whitelist: rules.opts.whitelist,
blacklist: rules.opts.blacklist,
middleware: options.get("middleware").toJS().concat(getPluginMiddleware(bs, scripts)),
middleware: options.get("middleware").toJS().concat(bs.pluginManager.hook("server:middleware")),
errHandler: function (err) {
bs.logger.debug("{red:[proxy error]} %s", err.message);
}
Expand All @@ -73,18 +74,6 @@ function getOptions (bs, scripts) {
return out;
}

/**
* Get proxy specific middleware
* @param bs
* @param scripts
* @returns {*}
*/
function getPluginMiddleware (bs, scripts) {
return bs.pluginManager.hook("server:middleware", [
snippetUtils.getProxyMiddleware(scripts, bs.options.getIn(["scriptPaths", "versioned"]))
]);
}

/**
* @param {Object} opts
* @param {Function} cb
Expand Down
14 changes: 0 additions & 14 deletions lib/snippet.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,6 @@ var utils = {
whitelist: options.get("whitelist").toJS()
};
},
/**
* @param {String} scripts - the client side JS
* @param {String} scriptPath - the URL to match
* @returns {Function}
*/
getProxyMiddleware: function (scripts, scriptPath) {
return function serveBsJavascriptfile (req, res, next) {
if (req.url.indexOf(scriptPath) > -1) {
res.writeHead(200, {"Content-Type": "text/javascript"});
return res.end(scripts);
}
next();
};
},
/**
* @param {Object} req
* @param {Array} [excludeList]
Expand Down

0 comments on commit c5fdbbf

Please sign in to comment.