diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..747d7d7 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +can-compile-proxy \ No newline at end of file diff --git a/.idea/can-compile-proxy.iml b/.idea/can-compile-proxy.iml new file mode 100644 index 0000000..c956989 --- /dev/null +++ b/.idea/can-compile-proxy.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..72abef0 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..bcb0607 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..75c1e41 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,205 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1455831904884 + + + 1455832655303 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lib/compile.js b/lib/compile.js index 6623e06..31bf88a 100644 --- a/lib/compile.js +++ b/lib/compile.js @@ -37,7 +37,7 @@ module.exports = function(options, callback) { return callback(new Error('A specific CanJS version number must be passed to compile views.')); } - visit(options.version, resolveScripts(options.version, options.paths), function(error, win) { + visit(options.version, resolveScripts(options.version, options.paths, options.proxy), function(error, win) { if (typeof options.log === 'function') { options.log('Compiling ' + filename); } diff --git a/lib/index.js b/lib/index.js index c274dc9..08aebcb 100644 --- a/lib/index.js +++ b/lib/index.js @@ -23,7 +23,8 @@ module.exports = function(files, configuration, callback, log) { extensions: configuration.extensions, viewAttributes: configuration.viewAttributes, version: configuration.version, - paths: configuration.paths + paths: configuration.paths, + proxy: configuration.proxy }, function(error, compiled, id) { if (error) { return callback(error); diff --git a/lib/resolveScripts.js b/lib/resolveScripts.js index 5f66fa1..4136cb0 100644 --- a/lib/resolveScripts.js +++ b/lib/resolveScripts.js @@ -39,20 +39,41 @@ var getScript = function(canVersion, script, paths) { } }; -var getPlugins = function(canVersion, paths) { +var getPlugins = function(canVersion, paths, proxy) { var plugins = []; for(var plugin in versionMap.plugins) { if(semver.satisfies(canVersion, versionMap.plugins[plugin])){ - plugins.push(getScript(canVersion, plugin, paths)); + plugins.push(proxyUrl(getScript(canVersion, plugin, paths), proxy)); } } return plugins; }; -module.exports = function(version, paths) { +var proxyUrl = function(url, proxy){ + if (!proxy) { + return url; + } + return { + host: proxy.host, + port: proxy.port, + path: url, + headers: { + Host: url + }, + + // fake function for doc-helpers + match : function(){ + return true; + } + }; +} + +module.exports = function(version, paths, proxy) { var scripts = []; - scripts.push(getjQuery(version, paths)); - scripts.push(getScript(version, 'can', paths)); - scripts = scripts.concat(getPlugins(version, paths)); + + scripts.push(proxyUrl(getjQuery(version, paths),proxy)); + scripts.push(proxyUrl(getScript(version, 'can', paths),proxy)); + scripts = scripts.concat(getPlugins(version, paths, proxy)); + return scripts; }; diff --git a/readme.md b/readme.md index 9c96903..b232f30 100644 --- a/readme.md +++ b/readme.md @@ -175,6 +175,7 @@ The options object allows the following configuration options: - `extensions` {Object}: An object to map custom file extensions to the standard extension (e.g. `{ 'mst' : 'mustache' }`) - `viewAttributes` {Array}: A list of attribute names (RegExp or String), used for additional behavior for an attribute in a view (can.view.attr) - `paths` an object with `ejs`, `mustache` or `stache` and a `jquery` property pointing to files of existing versions or CanJS and jQuery instead of the CDN links. +- `proxy` an object with `host` {String} and `port` {Number} properties ```javascript compiler.compile({