Skip to content

Commit 374744f

Browse files
bedirxanugurcreativecodetralexrudd2
authored
Fix static path for global install (#257)
Use import.meta.url for static files in global installs, which fixes an error "Cannot GET /" Co-authored-by: Bedirhan <[email protected]> Co-authored-by: Alex Ruddick <[email protected]>
1 parent 479f5f9 commit 374744f

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/server.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import http from "node:http";
99
import type { AddressInfo } from "node:net";
1010
import path from 'node:path';
11+
import { fileURLToPath } from 'node:url';
1112
import { autoDetect } from '@serialport/bindings-cpp';
1213
import type { PortInfo } from "@serialport/bindings-interface";
1314
import cors from "cors";
@@ -46,7 +47,8 @@ const getDeviceInfo = (ebb: EBB | null, _com: Com) => {
4647
*/
4748
export async function startServer(port: number, hardware: Hardware = 'v3', com: Com = null, enableCors = false, maxPayloadSize = '200mb', svgIoApiKey = '') {
4849
const app = express();
49-
app.use('/', express.static(path.join(path.resolve(), 'dist', 'ui')));
50+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
51+
app.use('/', express.static(path.join(__dirname, '..', 'ui')));
5052
app.use(express.json({ limit: maxPayloadSize }));
5153
if (enableCors) {
5254
app.use(cors());

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"$schema": "https://json.schemastore.org/tsconfig",
33
"compilerOptions": {
44
"target": "es2022",
5-
"module": "es2022",
5+
"module": "es2020",
66
"moduleResolution": "node",
77
"esModuleInterop": true,
88
"noImplicitAny": true,

0 commit comments

Comments
 (0)