Skip to content

Commit

Permalink
Merge pull request #669 from cmv/fix/updated-grunt-connect-with-proxy
Browse files Browse the repository at this point in the history
Updated grunt connect with proxy
  • Loading branch information
DavidSpriggs authored Feb 26, 2017
2 parents c7f1d76 + caeba31 commit 03088a5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
17 changes: 11 additions & 6 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ module.exports = function (grunt) {
// middleware for grunt.connect
var middleware = function (connect, options, middlewares) {
// inject a custom middleware into the array of default middlewares for proxy page
var bodyParser = require('body-parser');
var proxypage = require('proxypage');
var proxyRe = /\/proxy\/proxy.ashx/i;

var enableCORS = function (req, res, next) {
res.setHeader('Access-Control-Allow-Origin', req.headers.origin);
res.setHeader('Access-Control-Allow-Origin', req.headers.origin || '*');
res.setHeader('Access-Control-Allow-Credentials', true);
res.setHeader('Access-Control-Allow-Methods', 'GET,HEAD,PUT,PATCH,POST,DELETE');
res.setHeader('Access-Control-Allow-Headers', req.headers['access-control-request-headers']);
res.setHeader('Access-Control-Allow-Headers', req.headers['access-control-request-headers'] || 'Origin, X-Requested-With, Content-Type, Accept');
return next();
};

Expand All @@ -24,8 +25,8 @@ module.exports = function (grunt) {

middlewares.unshift(proxyMiddleware);
middlewares.unshift(enableCORS);
middlewares.unshift(connect.json()); //body parser, see https://github.com/senchalabs/connect/wiki/Connect-3.0
middlewares.unshift(connect.urlencoded()); //body parser
middlewares.unshift(bodyParser.json()); //body parser, see https://github.com/senchalabs/connect/wiki/Connect-3.0
middlewares.unshift(bodyParser.urlencoded({extended: true})); //body parser
return middlewares;
};

Expand Down Expand Up @@ -124,6 +125,8 @@ module.exports = function (grunt) {
port: 3000,
base: 'viewer',
hostname: '*',
protocol: 'https',
keepalive: true,
middleware: middleware
}
},
Expand All @@ -132,16 +135,18 @@ module.exports = function (grunt) {
port: 3001,
base: 'dist/viewer',
hostname: '*',
protocol: 'https',
keepalive: true,
middleware: middleware
}
}
},
open: {
'dev_browser': {
path: 'http://localhost:3000/index.html'
path: 'https://localhost:3000/index.html'
},
'build_browser': {
path: 'http://localhost:3001/index.html'
path: 'https://localhost:3001/index.html'
}
},
compress: {
Expand Down
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,27 @@
"version": "2.0.0-beta.1",
"author": "cmv.io - https://github.com/cmv/",
"license": "MIT",
"year": "2016",
"homepage": "http://cmv.io/",
"year": "2017",
"homepage": "https://cmv.io/",
"repository": "https://github.com/cmv/cmv-app/",
"dependencies": {
"babel-eslint": "6.1.x",
"babel-eslint": "~7.1.1",
"csslint": "1.0.x",
"eslint": "3.5.x",
"grunt": "1.0.x",
"grunt-contrib-clean": "1.0.x",
"grunt-contrib-compress": "1.3.x",
"grunt-contrib-compress": "~1.4.1",
"grunt-contrib-connect": "1.0.x",
"grunt-contrib-copy": "1.0.x",
"grunt-contrib-csslint": "1.0.x",
"grunt-contrib-csslint": "~2.0.x",
"grunt-contrib-cssmin": "1.0.x",
"grunt-contrib-uglify": "2.0.x",
"grunt-contrib-uglify": "2.1.x",
"grunt-contrib-watch": "1.0.x",
"grunt-eslint": "19.0.x",
"grunt-newer": "1.2.x",
"grunt-open": "0.2.x",
"grunt-postcss": "0.8.x",
"body-parser": "1.16.x",
"proxypage": "*"
},
"engine": "node >= 4",
Expand Down

0 comments on commit 03088a5

Please sign in to comment.