Browse Source

enable CORS, fixes #11

master
Lloyd Brookes 11 years ago
parent
commit
6df3ebff14
  1. 9
      bin/ws.js
  2. 3
      test/ajax.html

9
bin/ws.js

@ -66,9 +66,15 @@ if (argv.Misc.config){
dope.log(); dope.log();
process.exit(0); process.exit(0);
}); });
var app = connect(); var app = connect();
/* enable cross-origin requests on all resources */
app.use(function(req, res, next){
res.setHeader("Access-Control-Allow-Origin", "*");
next();
});
/* log using --log-format (if supplied) */ /* log using --log-format (if supplied) */
var logFormat = argv.Server["log-format"]; var logFormat = argv.Server["log-format"];
if(logFormat) { if(logFormat) {
@ -91,6 +97,7 @@ if (argv.Misc.config){
/* if no `--log-format` was specified, pipe the default format output /* if no `--log-format` was specified, pipe the default format output
into `log-stats`, which prints statistics to the console */ into `log-stats`, which prints statistics to the console */
} else { } else {
dope.hideCursor();
app.use(morgan({ stream: logStats({ refreshRate: argv.Server.refreshRate }) })); app.use(morgan({ stream: logStats({ refreshRate: argv.Server.refreshRate }) }));
} }

3
test/ajax.html

@ -9,8 +9,7 @@
<script> <script>
var $ = document.querySelector.bind(document); var $ = document.querySelector.bind(document);
var req = new XMLHttpRequest(); var req = new XMLHttpRequest();
req.open("get", "../README.md", true);
// req.open("get", "http://localhost:8010/README.md", true);
req.open("get", "http://localhost:8000/README.md", true);
req.onload = function(){ req.onload = function(){
$("#readme").textContent = this.responseText; $("#readme").textContent = this.responseText;
} }

Loading…
Cancel
Save