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

Adding contentType cli option to address #276 #288

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions bin/http-server
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ if (argv.h || argv.help) {
' -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',
' --contentType Use a custom Content-Type response header for all requests',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should match the style of other switches by using --content-type

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The contentType option actually is used for fallback, so maybe we could clarify by saying something like "Default Content-Type if it cannot be determined"?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possibly even more clear, though a long option, --default-content-type?

' -o [path] Open browser window after starting the server',
' -c Cache time (max-age) in seconds [3600], e.g. -c10 for 10 seconds.',
' To disable caching, use -c-1.',
Expand Down Expand Up @@ -109,6 +110,10 @@ function listen(port) {
}
}

if (argv.contentType) {
options.contentType = argv.contentType;
}

if (ssl) {
options.https = {
cert: argv.C || argv.cert || 'cert.pem',
Expand Down
4 changes: 4 additions & 0 deletions lib/http-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ function HttpServer(options) {
res.emit('next');
});

if (options.contentType) {
this.headers['Content-Type'] = options.contentType;
}

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