From 3ed726c9566ecb6ea5639f9dfcb9bfbbe6c8f543 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Tue, 22 Nov 2022 11:37:48 +0200 Subject: [PATCH] feat: option to disable /version query --- src/config/app.ts | 7 ++++++- src/http/index.ts | 14 ++++++++------ src/types/config/app.ts | 7 ++++++- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/config/app.ts b/src/config/app.ts index 6a2c0e9..20852f7 100644 --- a/src/config/app.ts +++ b/src/config/app.ts @@ -9,7 +9,9 @@ export const appConfig: AppConfig = { // Index page redirectIndex: 'https://iconify.design/', - // Region to add to `/version` response. Used to tell which server is responding when running multiple servers + // Region to add to `/version` response + // Used to tell which server is responding when running multiple servers + // Requires `enableVersion` to be enabled statusRegion: '', // Cache root directory @@ -33,6 +35,9 @@ export const appConfig: AppConfig = { // Delay to wait between successful update request and actual update updateThrottle: 60, + // Enables `/version` query + enableVersion: false, + // Enable icon sets and icon lists // Disable this option if you need API to serve only icon data to save memory enableIconLists: true, diff --git a/src/http/index.ts b/src/http/index.ts index 4476545..57fe2c7 100644 --- a/src/http/index.ts +++ b/src/http/index.ts @@ -178,12 +178,14 @@ export async function startHTTPServer() { }); // Version - server.get('/version', (req, res) => { - versionResponse(req.query, res); - }); - server.post('/version', (req, res) => { - versionResponse(req.query, res); - }); + if (appConfig.enableVersion) { + server.get('/version', (req, res) => { + versionResponse(req.query, res); + }); + server.post('/version', (req, res) => { + versionResponse(req.query, res); + }); + } // Redirect server.get('/', (req, res) => { diff --git a/src/types/config/app.ts b/src/types/config/app.ts index 827bec5..9d9c5cc 100644 --- a/src/types/config/app.ts +++ b/src/types/config/app.ts @@ -5,7 +5,9 @@ export interface AppConfig { // Index page redirectIndex: string; - // Region to add to `/version` response. Used to tell which server is responding when running multiple servers + // Region to add to `/version` response + // Used to tell which server is responding when running multiple servers + // Requires `enableVersion` to be enabled statusRegion: string; // Cache root directory @@ -30,6 +32,9 @@ export interface AppConfig { // Update check throttling updateThrottle: number; + // Enables `/version` query + enableVersion: boolean; + // Enable icon sets and icon lists // Disable this option if you need API to serve only icon data to save memory enableIconLists: boolean;