From 07a183a618aea3e1c7f63c8d9bb1fcb78a1e99e8 Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Fri, 17 Nov 2023 16:04:26 +0100 Subject: [PATCH] fix: properly resolve relative file Related: https://github.com/socketio/socket.io-website/commit/6a62d7d07bdd8a519775816c4d82d2745a2f595a --- index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index fff398f2..dee2243f 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,7 @@ import express from 'express'; import { createServer } from 'node:http'; +import { fileURLToPath } from 'node:url'; +import { dirname, join } from 'node:path'; import { Server } from 'socket.io'; import sqlite3 from 'sqlite3'; import { open } from 'sqlite'; @@ -37,8 +39,10 @@ if (cluster.isPrimary) { adapter: createAdapter() }); + const __dirname = dirname(fileURLToPath(import.meta.url)); + app.get('/', (req, res) => { - res.sendFile(new URL('./index.html', import.meta.url).pathname); + res.sendFile(join(__dirname, 'index.html')); }); io.on('connection', async (socket) => {