Skip to content

Commit

Permalink
CORS headers should apply to all responses
Browse files Browse the repository at this point in the history
  • Loading branch information
leo committed Feb 10, 2017
1 parent b7be348 commit 0919187
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@ const stream = require('send')
const renderDirectory = require('./render')

module.exports = async (req, res, flags, current, ignoredFiles) => {
const headers = {}

if (flags.cors) {
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept, Range'
}

for (const header in headers) {
if (!{}.hasOwnProperty.call(headers, header)) {
continue
}

res.setHeader(header, headers[header])
}

if (flags.auth) {
const credentials = auth(req)

Expand Down Expand Up @@ -100,21 +115,6 @@ module.exports = async (req, res, flags, current, ignoredFiles) => {
return stream(req, indexPath).pipe(res)
}

const headers = {}

if (flags.cors) {
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept, Range'
}

for (const header in headers) {
if (!{}.hasOwnProperty.call(headers, header)) {
continue
}

res.setHeader(header, headers[header])
}

// Serve files without a mime type as text
stream.mime.default_type = 'text/plain'

Expand Down

0 comments on commit 0919187

Please sign in to comment.