Skip to content
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ with the provided Dockerfile.
|`-b` or `--brotli`|When enabled it will serve `./public/some-file.js.br` in place of `./public/some-file.js` when a brotli compressed version of the file exists and the request accepts `br` encoding. If gzip is also enabled, it will try to serve brotli first. |`false`|
|`-e` or `--ext` |Default file extension if none supplied |`html` |
|`-s` or `--silent` |Suppress log messages from output | |
|`--cors` |Enable CORS via the `Access-Control-Allow-Origin` header | |
|`--cors` | Enable CORS via the `Access-Control-Allow-Origin: *` header. Optionally provide comma-separated values to add to `Access-Control-Allow-Headers` | |
|`-H` or `--header` |Add an extra response header (can be used several times) | |
|`-o [path]` |Open browser window after starting the server. Optionally provide a URL path to open. e.g.: -o /other/dir/ | |
|`-c` |Set cache time (in seconds) for cache-control max-age header, e.g. `-c10` for 10 seconds. To disable caching, use `-c-1`.|`3600` |
Expand Down
3 changes: 2 additions & 1 deletion bin/http-server
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ if (argv.h || argv.help) {
' -e --ext Default file extension if none supplied [none]',
' -s --silent Suppress log messages from output',
' --cors[=headers] Enable CORS via the "Access-Control-Allow-Origin" header',
' Optionally provide CORS headers list separated by commas',
' When enabled, sets Access-Control-Allow-Origin to "*"',
' Optional value adds to Access-Control-Allow-Headers',
' -H',
' --header',
' Add an extra response header (can be used several times)',
Expand Down
5 changes: 3 additions & 2 deletions doc/http-server.1
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ Suppress log messages from output.

.TP
.BI \-\-cors " " [\fIHEADERS\fR]
Enable CORS via the "Access-Control-Allow-Origin" header.
Optionally provide CORS headers list separated by commas.
Enable CORS by setting "Access-Control-Allow-Origin" to "*".
Optional comma-separated headers list adds to "Access-Control-Allow-Headers".
Default Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Range.

.TP
.BI \-H ", " \-\-header " " \fIHEADER\fR
Expand Down
3 changes: 3 additions & 0 deletions lib/http-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ function HttpServer(options) {
});
}

// CORS configuration:
// --cors enables CORS by setting Access-Control-Allow-Origin to '*'
// --cors=header1,header2 also adds custom headers to Access-Control-Allow-Headers
if (options.cors) {
this.headers['Access-Control-Allow-Origin'] = '*';
this.headers['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept, Range';
Expand Down
Loading