fix: use ESM imports instead of require in Electron main
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import { app, BrowserWindow, ipcMain, dialog } from 'electron';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { createServer } from 'http';
|
||||
import http from 'http';
|
||||
import fs from 'fs';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
@@ -44,9 +45,8 @@ function getDistPath() {
|
||||
|
||||
function loadDistServer() {
|
||||
const distPath = getDistPath();
|
||||
const indexPath = path.join(distPath, 'index.html');
|
||||
|
||||
const server = require('http').createServer((req, res) => {
|
||||
const server = http.createServer((req, res) => {
|
||||
let filePath = path.join(distPath, req.url === '/' ? 'index.html' : req.url);
|
||||
|
||||
if (!filePath.startsWith(distPath)) {
|
||||
@@ -67,7 +67,6 @@ function loadDistServer() {
|
||||
'.md': 'text/markdown',
|
||||
};
|
||||
|
||||
const fs = require('fs');
|
||||
if (fs.existsSync(filePath)) {
|
||||
const contentType = contentTypes[ext] || 'application/octet-stream';
|
||||
res.writeHead(200, { 'Content-Type': contentType });
|
||||
|
||||
Reference in New Issue
Block a user