-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.ts
41 lines (33 loc) · 966 Bytes
/
index.ts
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
40
41
import dotenv from 'dotenv';
import express, { Request, Response } from 'express';
import mongoose from 'mongoose';
import eventsRouter from './src/routes/events';
import cors from 'cors';
dotenv.config();
const PORT = process.env.PORT || 5050;
const app = express();
app.use(
cors({
origin: '*',
})
);
const mongoConnectOptions: mongoose.ConnectOptions = {
keepAlive: true,
keepAliveInitialDelay: 300000,
heartbeatFrequencyMS: 10000,
};
const MONGO_URI = process.env.MONGO_URI;
if (!MONGO_URI) {
throw new Error('MONGO_URI is not defined!');
}
mongoose
.connect(MONGO_URI, mongoConnectOptions)
.then(() => console.log('Connected to MongoDB'))
.catch((err) => console.log(err));
const healthHandler = (_: Request, res: Response) => res.send("I'm alive!");
app.get('/', healthHandler);
app.get('/health', healthHandler);
app.use('/events', eventsRouter);
app.listen(PORT, () => {
console.log(`OSAI Core running on port: ${PORT}`);
});