serve-handler
Advanced tools
Comparing version 3.2.3 to 3.3.0
{ | ||
"name": "serve-handler", | ||
"version": "3.2.3", | ||
"version": "3.3.0", | ||
"description": "The routing foundation of `serve` and static deployments on Now", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -195,17 +195,21 @@ // Native | ||
const defaultHeaders = { | ||
'Last-Modified': stats.mtime.toUTCString(), | ||
'Content-Length': stats.size, | ||
// Default to "inline", which always tries to render in the browser, | ||
// if that's not working, it will save the file. But to be clear: This | ||
// only happens if it cannot find a appropiate value. | ||
'Content-Disposition': contentDisposition(base, { | ||
type: 'inline' | ||
}) | ||
}; | ||
let defaultHeaders = {}; | ||
const contentType = mime.contentType(base); | ||
if (stats) { | ||
defaultHeaders = { | ||
'Last-Modified': stats.mtime.toUTCString(), | ||
'Content-Length': stats.size, | ||
// Default to "inline", which always tries to render in the browser, | ||
// if that's not working, it will save the file. But to be clear: This | ||
// only happens if it cannot find a appropiate value. | ||
'Content-Disposition': contentDisposition(base, { | ||
type: 'inline' | ||
}) | ||
}; | ||
if (contentType) { | ||
defaultHeaders['Content-Type'] = contentType; | ||
const contentType = mime.contentType(base); | ||
if (contentType) { | ||
defaultHeaders['Content-Type'] = contentType; | ||
} | ||
} | ||
@@ -426,3 +430,3 @@ | ||
const sendError = async (response, acceptsJSON, current, handlers, config, spec) => { | ||
const sendError = async (absolutePath, response, acceptsJSON, current, handlers, config, spec) => { | ||
const {err: original, message, code, statusCode} = spec; | ||
@@ -459,3 +463,3 @@ | ||
// eslint-disable-next-line no-use-before-define | ||
return internalError(response, acceptsJSON, current, handlers, config, err); | ||
return internalError(absolutePath, response, acceptsJSON, current, handlers, config, err); | ||
} | ||
@@ -474,3 +478,6 @@ } | ||
response.setHeader('Content-Type', 'text/html; charset=utf-8'); | ||
const headers = await getHeaders(config.headers, current, absolutePath, null); | ||
headers['Content-Type'] = 'text/html; charset=utf-8'; | ||
response.writeHead(statusCode, headers); | ||
response.end(errorTemplate({statusCode, message})); | ||
@@ -508,3 +515,3 @@ }; | ||
} catch (err) { | ||
return sendError(response, acceptsJSON, current, handlers, config, { | ||
return sendError('/', response, acceptsJSON, current, handlers, config, { | ||
statusCode: 400, | ||
@@ -521,3 +528,3 @@ code: 'bad_request', | ||
if (!isPathInside(absolutePath, current)) { | ||
return sendError(response, acceptsJSON, current, handlers, config, { | ||
return sendError(absolutePath, response, acceptsJSON, current, handlers, config, { | ||
statusCode: 400, | ||
@@ -560,3 +567,3 @@ code: 'bad_request', | ||
if (err.code !== 'ENOENT') { | ||
return internalError(response, acceptsJSON, current, handlers, config, err); | ||
return internalError(absolutePath, response, acceptsJSON, current, handlers, config, err); | ||
} | ||
@@ -577,3 +584,3 @@ } | ||
if (err.code !== 'ENOENT') { | ||
return internalError(response, acceptsJSON, current, handlers, config, err); | ||
return internalError(absolutePath, response, acceptsJSON, current, handlers, config, err); | ||
} | ||
@@ -588,3 +595,3 @@ } | ||
if (err.code !== 'ENOENT') { | ||
return internalError(response, acceptsJSON, current, handlers, config, err); | ||
return internalError(absolutePath, response, acceptsJSON, current, handlers, config, err); | ||
} | ||
@@ -611,3 +618,3 @@ } | ||
if (err.code !== 'ENOENT') { | ||
return internalError(response, acceptsJSON, current, handlers, config, err); | ||
return internalError(absolutePath, response, acceptsJSON, current, handlers, config, err); | ||
} | ||
@@ -634,3 +641,3 @@ } | ||
if (!stats) { | ||
return sendError(response, acceptsJSON, current, handlers, config, { | ||
return sendError(absolutePath, response, acceptsJSON, current, handlers, config, { | ||
statusCode: 404, | ||
@@ -637,0 +644,0 @@ code: 'not_found', |
38376
552