37 lines
996 B
TypeScript
37 lines
996 B
TypeScript
import app from '../api/app';
|
|
import path from 'path';
|
|
import express from 'express';
|
|
import { fileURLToPath } from 'url';
|
|
import { logger } from '../api/utils/logger';
|
|
import { AddressInfo } from 'net';
|
|
import { startWatcher } from '../api/watcher/watcher.js';
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = path.dirname(__filename);
|
|
|
|
startWatcher();
|
|
|
|
const distPath = path.join(__dirname, '../dist');
|
|
|
|
app.use(express.static(distPath));
|
|
|
|
app.get('*', (req, res) => {
|
|
res.sendFile(path.join(distPath, 'index.html'));
|
|
});
|
|
|
|
export const startServer = (): Promise<number> => {
|
|
return new Promise((resolve, reject) => {
|
|
const server = app.listen(0, () => {
|
|
const address = server.address() as AddressInfo;
|
|
const port = address.port;
|
|
logger.info(`Electron internal server running on port ${port}`);
|
|
resolve(port);
|
|
});
|
|
|
|
server.on('error', (err) => {
|
|
logger.error('Failed to start server:', err);
|
|
reject(err);
|
|
});
|
|
});
|
|
};
|