Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated grunt connect with proxy #669

Merged
merged 4 commits into from
Feb 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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