From 276fec6e50e7744b2ee88acbcf12b2146ce54f67 Mon Sep 17 00:00:00 2001 From: Thierry Templier Date: Thu, 25 Feb 2016 09:28:01 +0100 Subject: [PATCH] build(serve): added cors support for the js.server task Added and used the cors middleware: - add the module as a dev depedency in the package.json file - require the module in the jsserve.js file - add the module in the middleware list Closes #7273 Closes #7274 --- npm-shrinkwrap.clean.json | 3 +++ npm-shrinkwrap.json | 5 +++++ package.json | 1 + tools/build/jsserve.js | 2 ++ 4 files changed, 11 insertions(+) diff --git a/npm-shrinkwrap.clean.json b/npm-shrinkwrap.clean.json index cc3d3c171a..f18592314e 100644 --- a/npm-shrinkwrap.clean.json +++ b/npm-shrinkwrap.clean.json @@ -1831,6 +1831,9 @@ "core-util-is": { "version": "1.0.2" }, + "cors": { + "version": "2.7.1" + }, "crc": { "version": "3.3.0" }, diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 49504db357..6748101fbd 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -2871,6 +2871,11 @@ "from": "core-util-is@>=1.0.0 <1.1.0", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz" }, + "cors": { + "version": "2.7.1", + "from": "cors@>=2.7.1 <3.0.0", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.7.1.tgz" + }, "crc": { "version": "3.3.0", "from": "crc@3.3.0", diff --git a/package.json b/package.json index 6a4d9a0108..053236f835 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "chokidar": "^1.1.0", "clang-format": "^1.0.32", "conventional-changelog": "^0.2.1", + "cors": "^2.7.1", "firefox-profile": "^0.3.4", "fs-extra": "^0.26.3", "glob": "^4.0.6", diff --git a/tools/build/jsserve.js b/tools/build/jsserve.js index 434a2f8e1d..123a1ecc77 100644 --- a/tools/build/jsserve.js +++ b/tools/build/jsserve.js @@ -1,5 +1,6 @@ var onHeaders = require('on-headers'); var proxy = require('proxy-middleware'); +var cors = require('cors'); var url = require('url'); module.exports = function(gulp, plugins, config) { @@ -14,6 +15,7 @@ module.exports = function(gulp, plugins, config) { var middlewares = config.proxies.map(function(entry) { return makeProxy(entry.route, entry.url); }); middlewares.push(connect.favicon()); + middlewares.push(cors()); // pub serve can't give the right content-type header for jsonp requests // so we must turn off Chromium strict MIME type checking // see https://github.com/angular/angular/issues/3030#issuecomment-123453168