serve-handler
Advanced tools
Comparing version 2.3.16 to 2.4.0
{ | ||
"name": "serve-handler", | ||
"version": "2.3.16", | ||
"version": "2.4.0", | ||
"description": "The routing foundation of `serve` and static deployments on Now", | ||
@@ -63,2 +63,3 @@ "main": "src/index.js", | ||
"bytes": "3.0.0", | ||
"content-disposition": "0.5.2", | ||
"fast-url-parser": "1.1.3", | ||
@@ -65,0 +66,0 @@ "glob-slasher": "1.0.1", |
@@ -13,2 +13,3 @@ // Native | ||
const bytes = require('bytes'); | ||
const contentDisposition = require('content-disposition'); | ||
const isPathInside = require('path-is-inside'); | ||
@@ -175,4 +176,6 @@ | ||
const getHeaders = async (customHeaders = [], relativePath, rewrittenPath, stats) => { | ||
const getHeaders = async (customHeaders = [], current, absolutePath, stats) => { | ||
const related = {}; | ||
const {base} = path.parse(absolutePath); | ||
const relativePath = path.relative(current, absolutePath); | ||
@@ -186,3 +189,3 @@ if (customHeaders.length > 0) { | ||
if (sourceMatches(source, relativePath)) { | ||
if (sourceMatches(source, slasher(relativePath))) { | ||
appendHeaders(related, headers); | ||
@@ -195,7 +198,12 @@ } | ||
'Last-Modified': stats.mtime.toUTCString(), | ||
'Content-Length': stats.size | ||
'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' | ||
}) | ||
}; | ||
const getBase = target => (target ? path.parse(target).base : ''); | ||
const contentType = mime.contentType(getBase(relativePath)) || mime.contentType(getBase(rewrittenPath)); | ||
const contentType = mime.contentType(base); | ||
@@ -254,4 +262,3 @@ if (contentType) { | ||
stats, | ||
absolutePath, | ||
rewrittenPath: related | ||
absolutePath | ||
}; | ||
@@ -409,4 +416,4 @@ } | ||
const handlers = getHandlers(methods); | ||
const relativePath = decodeURIComponent(url.parse(request.url).pathname); | ||
let relativePath = decodeURIComponent(url.parse(request.url).pathname); | ||
let absolutePath = path.join(current, relativePath); | ||
@@ -448,3 +455,3 @@ | ||
let rewrittenPath = applyRewrites(relativePath, config.rewrites); | ||
const rewrittenPath = applyRewrites(relativePath, config.rewrites); | ||
@@ -456,3 +463,3 @@ if ((!stats || stats.isDirectory()) && (cleanUrl || rewrittenPath)) { | ||
if (related) { | ||
({stats, absolutePath, rewrittenPath} = related); | ||
({stats, absolutePath} = related); | ||
} | ||
@@ -525,7 +532,6 @@ } catch (err) { | ||
const errorPage = '404.html'; | ||
const errorPageFull = path.join(current, errorPage); | ||
const errorPage = path.join(current, '404.html'); | ||
try { | ||
stats = await handlers.stat(errorPageFull); | ||
stats = await handlers.stat(errorPage); | ||
} catch (err) { | ||
@@ -545,7 +551,6 @@ if (err.code !== 'ENOENT') { | ||
absolutePath = errorPageFull; | ||
relativePath = errorPage; | ||
absolutePath = errorPage; | ||
} | ||
const headers = await getHeaders(config.headers, relativePath, rewrittenPath, stats); | ||
const headers = await getHeaders(config.headers, current, absolutePath, stats); | ||
const stream = await handlers.createReadStream(absolutePath); | ||
@@ -552,0 +557,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31452
459
8
+ Addedcontent-disposition@0.5.2
+ Addedcontent-disposition@0.5.2(transitive)