-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ts
More file actions
34 lines (28 loc) · 1.24 KB
/
main.ts
File metadata and controls
34 lines (28 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import 'reflect-metadata';
import path from 'node:path';
import { NestFactory } from '@nestjs/core';
import { MicroserviceOptions } from '@nestjs/microservices';
import { ElectronIPCTransport } from 'nestjs-electron-ipc-transport';
import { AppModule } from './app.module.js';
import { applyFixPath } from './fix-path-bootstrap.js';
import { createLogger } from './logger.js';
applyFixPath();
// ElectronIPCTransport requires ipcMain, which is only available inside an
// Electron main process. Fail fast with a readable message rather than a
// cryptic module-resolution error when someone runs `node dist/main.js`.
// This guard must run before any Electron API calls (e.g. app.getPath).
if (!process.versions['electron']) {
throw new Error(
'desktop-main must run inside an Electron main process. ' +
'Launch via Electron — running with plain Node is not supported.',
);
}
const { app } = await import('electron') as unknown as { app: { getPath(name: string): string } };
createLogger(path.join(app.getPath('userData'), 'logs'));
async function bootstrap(): Promise<void> {
const app = await NestFactory.createMicroservice<MicroserviceOptions>(AppModule, {
strategy: new ElectronIPCTransport(),
});
await app.listen();
}
void bootstrap();