Skip to content

Commit 99e0deb

Browse files
MichalCzBudleigh Salterton
authored and
Budleigh Salterton
committed
cors headers work in progress
1 parent a9e160d commit 99e0deb

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

bin/http-server

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ function listen(port) {
105105
options.cors = true;
106106
}
107107

108+
if (argv.corsheaders) {
109+
options.cors_headers = argv.corsheaders;
110+
}
111+
108112
if (ssl) {
109113
options.https = {
110114
cert: argv.C || argv.cert || 'cert.pem',

lib/http-server.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,13 @@ function HttpServer(options) {
6767
if (options.cors) {
6868
this.headers['Access-Control-Allow-Origin'] = '*';
6969
this.headers['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept, Range';
70-
71-
before.push(corser.create());
70+
if (options.cors_headers) {
71+
options.cors_headers.split(/\s*,\s*/)
72+
.forEach(function(h){ console.log(h); this.headers['Access-Control-Allow-Headers'] += ', ' + h; }, this);
73+
}
74+
before.push(corser.create(options.cors_headers ? {
75+
requestHeaders: this.headers['Access-Control-Allow-Headers'].split(/\s*,\s*/)
76+
} : null));
7277
}
7378

7479
if (options.robots) {

0 commit comments

Comments
 (0)