feat: allow disabling built-in routes

intenteded for more advanced users
more of a shortcut, since they could always edit the codes themselves

please consult comments in sample config file
This commit is contained in:
Bobby 2022-09-21 05:53:45 +07:00
parent 4b55f33243
commit 0cb02a5c6c
No known key found for this signature in database
GPG Key ID: 941839794CBF5A09
2 changed files with 30 additions and 4 deletions

View File

@ -104,6 +104,25 @@ module.exports = {
*/
cookiePolicy: false,
/*
Additional routes that come with their own frontend pages logic (in routes/routeName.js).
These routes will always be enabled by default, even if the option below is missing,
so they need to be explicitly set to false to disable.
NOTE: Some frontend scripts in dashboard, etc., will always assume that they are all enabled,
so they may end up with dead links if disabled (i.e. file info button in dashboard),
but otherwise their other own main functions should remain working.
In short, this is mainly intended for those who know what they are doing,
and are willing to modify the scripts themselves when required.
*/
routes: {
album: true,
file: true,
nojs: true,
player: true
},
/*
This can be either 'blacklist' or 'whitelist', which should be self-explanatory.
When this is set to neither, this will fallback to 'blacklist'.

View File

@ -219,10 +219,17 @@ const serveStaticPublicInstance = new ServeStaticClass(paths.public, {
safe.use(serveStaticPublicInstance.middleware)
// Routes
safe.use(album)
safe.use(file)
safe.use(nojs)
safe.use(player)
config.routes = typeof config.routes === 'object'
? config.routes
: {}
// Only disable these routes if they are explicitly set to false in config file
if (config.routes.album !== false) safe.use(album)
if (config.routes.file !== false) safe.use(file)
if (config.routes.nojs !== false) safe.use(nojs)
if (config.routes.player !== false) safe.use(player)
// API routes
safe.use('/api', api)
;(async () => {