Initial commit
This commit is contained in:
36
electron/server.ts
Normal file
36
electron/server.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
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);
|
||||
});
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user