feat: env SERVE_STATIC_QUICK=0 yarn start

restore an older behavior of serving static files with
ServeLiveDirectory middleware instead of ServeStaticQuick, in case of
issues with streaming files from disk via createReadStream

if you do encounter this issue, serving uploaded files with node will
likely encounter issues as well, but you can choose to serve them
directly with nginx, etc., so i guess it's not beyond hope
This commit is contained in:
Bobby 2022-08-21 21:23:14 +07:00
parent 3f08b966ef
commit 09fea107f3
No known key found for this signature in database
GPG Key ID: 941839794CBF5A09
2 changed files with 12 additions and 8 deletions

View File

@ -22,7 +22,8 @@ const self = {
// Allow some config options to be overriden via env vars
port: process.env.PORT || config.port,
domain: process.env.DOMAIN || config.domain,
homeDomain: process.env.HOME_DOMAIN || config.homeDomain
homeDomain: process.env.HOME_DOMAIN || config.homeDomain,
disableServeStaticQuick: process.env.SERVE_STATIC_QUICK === '0'
},
scan: {
instance: null,

View File

@ -191,17 +191,20 @@ if (config.cacheControl) {
})
}
// Init ServeStaticQuick middlewares for static assets
// Init serve static middlewares for static assets
const ServeStaticClass = utils.conf.disableServeStaticQuick
? ServeLiveDirectory
: ServeStaticQuick
// Static assets in /dist directory
const serveStaticQuickDistInstance = new ServeStaticQuick(paths.dist, {
const serveStaticDistInstance = new ServeStaticClass(paths.dist, {
setHeaders: setHeadersForStaticAssets
})
safe.use(serveStaticQuickDistInstance.middleware)
safe.use(serveStaticDistInstance.middleware)
// Static assets in /public directory
const serveStaticQuickPublicInstance = new ServeStaticQuick(paths.public, {
const serveStaticPublicInstance = new ServeStaticClass(paths.public, {
setHeaders: setHeadersForStaticAssets
})
safe.use(serveStaticQuickPublicInstance.middleware)
safe.use(serveStaticPublicInstance.middleware)
// Routes
safe.use(album)
@ -313,8 +316,8 @@ safe.use('/api', api)
// Await all ServeLiveDirectory and ServeStaticQuick instances
await Promise.all([
serveStaticQuickDistInstance.ready(),
serveStaticQuickPublicInstance.ready(),
serveStaticDistInstance.ready(),
serveStaticPublicInstance.ready(),
serveLiveDirectoryCustomPagesInstance.ready()
])