Skip to content

Commit

Permalink
Feat: option --allow-cors for resource sharing
Browse files Browse the repository at this point in the history
  • Loading branch information
Offirmo committed Aug 6, 2018
1 parent 16b8d72 commit aed4a19
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Options:
-t,--target <url> remote proxy server
--no-reload close auto-reload feature,(not recommended)
--no-launch close the auto launch feature
--allow-cors allow cross origin resource sharing
-h,--help help list

```
Expand Down
4 changes: 3 additions & 1 deletion src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ program
.option('--views <path>', 'change the template\' folder, default is ./views')
.option('--no-reload', 'stop livereload')
.option('--no-launch', 'stop autolaunch page in browser')
.option('--allow-cors', 'allow CORS for all origins')



Expand All @@ -62,7 +63,8 @@ program.once('done', function(createFile){
views: program.views,
reload: program.reload,
launch: program.launch,
engine: program.engine
engine: program.engine,
allowCORS: program.allowCors,
}


Expand Down
10 changes: 9 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,15 @@ var puer = module.exports = function ( options ){
options.server = server;
app.use( livereload (options))
}


if (options.allowCORS) {
// Allow Cross Origin Resource Sharing
// https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
app.use(function (req, res, next) {
res.setHeader("Access-Control-Allow-Origin", "*");
return next();
});
}

if(options.rules){ app.use( rewrite( options ) ); }
app.use( folder( options ) );
Expand Down

0 comments on commit aed4a19

Please sign in to comment.