From 0cb02a5c6c5979d77651bf6808f2dd8f7cfb79eb Mon Sep 17 00:00:00 2001 From: Bobby Date: Wed, 21 Sep 2022 05:53:45 +0700 Subject: [PATCH] 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 --- config.sample.js | 19 +++++++++++++++++++ lolisafe.js | 15 +++++++++++---- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/config.sample.js b/config.sample.js index 4c25830..88c25e0 100644 --- a/config.sample.js +++ b/config.sample.js @@ -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'. diff --git a/lolisafe.js b/lolisafe.js index a1fc87d..32a53e1 100644 --- a/lolisafe.js +++ b/lolisafe.js @@ -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 () => {