mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2024-12-13 16:06:21 +00:00
refactor: overrideContentTypes
This commit is contained in:
parent
1404cf9328
commit
ad4c2c2e96
23
lolisafe.js
23
lolisafe.js
@ -120,8 +120,9 @@ safe.use(bodyParser.json())
|
|||||||
const cdnPages = [...config.pages]
|
const cdnPages = [...config.pages]
|
||||||
let setHeaders
|
let setHeaders
|
||||||
|
|
||||||
const contentTypes = config.overrideContentTypes && Object.keys(config.overrideContentTypes)
|
const contentTypes = typeof config.overrideContentTypes === 'object' &&
|
||||||
const overrideContentTypes = (res, path) => {
|
Object.keys(config.overrideContentTypes)
|
||||||
|
const overrideContentTypes = contentTypes && contentTypes.length && function (res, path) {
|
||||||
// Do only if accessing files from uploads' root directory (i.e. not thumbs, etc.)
|
// Do only if accessing files from uploads' root directory (i.e. not thumbs, etc.)
|
||||||
const relpath = path.replace(paths.uploads, '')
|
const relpath = path.replace(paths.uploads, '')
|
||||||
if (relpath.indexOf('/', 1) === -1) {
|
if (relpath.indexOf('/', 1) === -1) {
|
||||||
@ -201,8 +202,8 @@ if (config.cacheControl) {
|
|||||||
if (config.serveFilesWithNode) {
|
if (config.serveFilesWithNode) {
|
||||||
initServeStaticUploads({
|
initServeStaticUploads({
|
||||||
setHeaders: (res, path) => {
|
setHeaders: (res, path) => {
|
||||||
// Override Content-Type if necessary
|
// Override Content-Type header if necessary
|
||||||
if (contentTypes && contentTypes.length) {
|
if (overrideContentTypes) {
|
||||||
overrideContentTypes(res, path)
|
overrideContentTypes(res, path)
|
||||||
}
|
}
|
||||||
// If using CDN, cache uploads in CDN as well
|
// If using CDN, cache uploads in CDN as well
|
||||||
@ -232,14 +233,12 @@ if (config.cacheControl) {
|
|||||||
next()
|
next()
|
||||||
})
|
})
|
||||||
} else if (config.serveFilesWithNode) {
|
} else if (config.serveFilesWithNode) {
|
||||||
initServeStaticUploads({
|
const opts = {}
|
||||||
setHeaders: (res, path) => {
|
// Override Content-Type header if necessary
|
||||||
// Override Content-Type if necessary
|
if (overrideContentTypes) {
|
||||||
if (contentTypes && contentTypes.length) {
|
opts.setHeaders = overrideContentTypes
|
||||||
overrideContentTypes(res, path)
|
}
|
||||||
}
|
initServeStaticUploads(opts)
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Static assets
|
// Static assets
|
||||||
|
Loading…
Reference in New Issue
Block a user