Skip to content

Commit 1727deb

Browse files
fix: use import.meta.url for ESM __dirname in dashboard plugin
Plugin used __dirname which is undefined in ESM modules. Replaced with fileURLToPath(import.meta.url) pattern matching server.ts.
1 parent 17bdda2 commit 1727deb

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

src/plugins/dashboard-static.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import fastifyStatic from '@fastify/static';
1717
import fs from 'node:fs/promises';
1818
import { statSync } from 'node:fs';
1919
import path from 'node:path';
20+
import { fileURLToPath } from 'node:url';
2021

2122
import { logger } from '../logger.js';
2223

@@ -94,6 +95,8 @@ export async function registerDashboardStatic(
9495
app: FastifyInstance,
9596
options: DashboardStaticOptions = {}
9697
): Promise<boolean> {
98+
const __filename = fileURLToPath(import.meta.url);
99+
const __dirname = path.dirname(__filename);
97100
const dashboardRoot = path.join(__dirname, '..', 'dashboard');
98101
const dashboardEnabled = options.enabled !== false;
99102
let dashboardAvailable = false;

0 commit comments

Comments
 (0)