From e2a802d58ff9e7bb474b278ae466709c11c095fa Mon Sep 17 00:00:00 2001 From: Jamie Hewitt Date: Wed, 13 Mar 2024 14:58:29 +0300 Subject: [PATCH 1/3] Making the dashboard optional --- src/@types/OceanNode.ts | 1 + src/index.ts | 32 +++++++++++++++++--------------- src/utils/config.ts | 1 + src/utils/constants.ts | 5 +++++ 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/@types/OceanNode.ts b/src/@types/OceanNode.ts index 2b65318f5..bf71aaee1 100644 --- a/src/@types/OceanNode.ts +++ b/src/@types/OceanNode.ts @@ -40,6 +40,7 @@ export interface OceanNodeConfig { hasIndexer: boolean hasProvider: boolean hasHttp: boolean + hasDashboard: boolean dbConfig?: OceanNodeDBConfig httpPort: number feeStrategy: FeeStrategy diff --git a/src/index.ts b/src/index.ts index 7e3f365b5..fb65edc60 100644 --- a/src/index.ts +++ b/src/index.ts @@ -125,22 +125,24 @@ if (config.hasHttp) { app.use(express.raw({ limit: '25mb' })) app.use(cors()) - // Serve static files expected at the root, under the '/_next' path - app.use('/_next', express.static(path.join(__dirname, '/dashboard/_next'))) - - // Serve static files for Next.js under '/dashboard' - const dashboardPath = path.join(__dirname, '/dashboard') - app.use('/dashboard', express.static(dashboardPath)) - - // Custom middleware for SPA routing: Serve index.html for non-static asset requests under '/dashboard' - app.use('/dashboard', (req, res, next) => { - if (/(.ico|.js|.css|.jpg|.png|.svg|.map)$/i.test(req.path)) { - return next() // Skip this middleware if the request is for a static asset - } + if (config.hasDashboard) { + // Serve static files expected at the root, under the '/_next' path + app.use('/_next', express.static(path.join(__dirname, '/dashboard/_next'))) + + // Serve static files for Next.js under '/dashboard' + const dashboardPath = path.join(__dirname, '/dashboard') + app.use('/dashboard', express.static(dashboardPath)) + + // Custom middleware for SPA routing: Serve index.html for non-static asset requests under '/dashboard' + app.use('/dashboard', (req, res, next) => { + if (/(.ico|.js|.css|.jpg|.png|.svg|.map)$/i.test(req.path)) { + return next() // Skip this middleware if the request is for a static asset + } - // For any other requests under '/dashboard', serve index.html - res.sendFile(path.join(dashboardPath, 'index.html')) - }) + // For any other requests under '/dashboard', serve index.html + res.sendFile(path.join(dashboardPath, 'index.html')) + }) + } // allow up to 25Mb file upload app.use((req, res, next) => { diff --git a/src/utils/config.ts b/src/utils/config.ts index b4c0cc73c..bdaab1887 100644 --- a/src/utils/config.ts +++ b/src/utils/config.ts @@ -405,6 +405,7 @@ async function getEnvConfig(isStartup?: boolean): Promise { }, // Only enable provider if we have a DB_URL hasProvider: !!getEnvValue(process.env.DB_URL, ''), + hasDashboard: !!getEnvValue(process.env.DASHBOARD, true), httpPort: getIntEnvValue(process.env.HTTP_API_PORT, 8000), dbConfig: { url: getEnvValue(process.env.DB_URL, '') diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 4749e1163..654fc7b0a 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -194,5 +194,10 @@ export const ENVIRONMENT_VARIABLES: Record = { name: 'ALLOWED_ADMINS', value: process.env.ALLOWED_ADMINS, required: false + }, + DASHBOARD: { + name: 'DASHBOARD', + value: process.env.DASHBOARD, + required: false } } From 7224abb3839e89a92064fab17e970c10c84bc6a0 Mon Sep 17 00:00:00 2001 From: Jamie Hewitt Date: Wed, 13 Mar 2024 15:18:37 +0300 Subject: [PATCH 2/3] Setting hasDashboard in config.ts --- src/utils/config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/config.ts b/src/utils/config.ts index bdaab1887..0f5e30146 100644 --- a/src/utils/config.ts +++ b/src/utils/config.ts @@ -405,7 +405,7 @@ async function getEnvConfig(isStartup?: boolean): Promise { }, // Only enable provider if we have a DB_URL hasProvider: !!getEnvValue(process.env.DB_URL, ''), - hasDashboard: !!getEnvValue(process.env.DASHBOARD, true), + hasDashboard: process.env.DASHBOARD !== 'false', httpPort: getIntEnvValue(process.env.HTTP_API_PORT, 8000), dbConfig: { url: getEnvValue(process.env.DB_URL, '') From dbde48b324e3f0816bc08620a6a4b2ec7a93f5b4 Mon Sep 17 00:00:00 2001 From: Jamie Hewitt Date: Tue, 19 Mar 2024 17:26:21 +0300 Subject: [PATCH 3/3] Adding DASHBOARD env to env.md --- env.md | 1 + 1 file changed, 1 insertion(+) diff --git a/env.md b/env.md index 60a79116b..5e2b92bb1 100644 --- a/env.md +++ b/env.md @@ -23,3 +23,4 @@ Environmental variables are also tracked in `ENVIRONMENT_VARIABLES` within `src/ | ALLOWED_VALIDATORS | false | "[\"0x123\",\"0x456\"]" | Array of addresses for allowed validators to verify asset signatures before indexing. | | INDEXER_INTERVAL | false | 10000 | Sets the interval in milliseconds for the indexer to crawl. The default is 30 seconds if not set. | | ALLOWED_ADMINS | false | "[\"0x967da4048cD07aB37855c090aAF366e4ce1b9F48\",\"0x388C818CA8B9251b393131C08a736A67ccB19297\"]" | Sets the public address of accounts which have access to admin endpoints e.g. shutting down the node. | +| DASHBOARD | false | "false" | If `false` the dashboard will not run. If not set or `true` the dashboard will start with the node. |