-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.ts
More file actions
39 lines (30 loc) · 1.18 KB
/
server.ts
File metadata and controls
39 lines (30 loc) · 1.18 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
35
36
37
38
39
import dotenv from 'dotenv';
import createApp from './src/app';
import ProviderInitializer from './src/services/providerInitializer';
import logger from './src/utils/logger';
import getServer from './src/grpcServer';
import * as grpc from '@grpc/grpc-js';
dotenv.config();
async function startServer() {
try {
logger.info('>>> Initializing providers <<<');
await ProviderInitializer.initializeAllProviders();
logger.info('>>> Creating the app <<<');
const app = await createApp();
logger.info('>>> Starting the server <<<');
const PORT = process.env.PORT || 3010;
app.listen(PORT, () => {
logger.info(`Server is running on port ${PORT}`);
});
logger.info('>>> Starting gRPC server <<<');
const server = getServer();
const GRPC_PORT = process.env.GRPC_PORT || 50052;
server.bindAsync(`0.0.0.0:${GRPC_PORT}`, grpc.ServerCredentials.createInsecure(), () => {
logger.info(`gRPC server running at http://0.0.0.0:${GRPC_PORT}`);
});
} catch (error: any) {
logger.error(`Failed to start server: ${error.message}`);
process.exit(1);
}
}
startServer();