Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making the dashboard optional #338

Merged
merged 5 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/@types/OceanNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export interface OceanNodeConfig {
hasIndexer: boolean
hasProvider: boolean
hasHttp: boolean
hasDashboard: boolean
dbConfig?: OceanNodeDBConfig
httpPort: number
feeStrategy: FeeStrategy
Expand Down
32 changes: 17 additions & 15 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
1 change: 1 addition & 0 deletions src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ async function getEnvConfig(isStartup?: boolean): Promise<OceanNodeConfig> {
},
// Only enable provider if we have a DB_URL
hasProvider: !!getEnvValue(process.env.DB_URL, ''),
hasDashboard: process.env.DASHBOARD !== 'false',
httpPort: getIntEnvValue(process.env.HTTP_API_PORT, 8000),
dbConfig: {
url: getEnvValue(process.env.DB_URL, '')
Expand Down
5 changes: 5 additions & 0 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,5 +194,10 @@ export const ENVIRONMENT_VARIABLES: Record<any, EnvVariable> = {
name: 'ALLOWED_ADMINS',
value: process.env.ALLOWED_ADMINS,
required: false
},
DASHBOARD: {
name: 'DASHBOARD',
value: process.env.DASHBOARD,
required: false
}
}
Loading