forked from ftoucch/weblit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
52 lines (43 loc) · 1.38 KB
/
server.js
File metadata and controls
52 lines (43 loc) · 1.38 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
40
41
42
43
44
45
46
47
48
49
50
51
52
import express from 'express';
import dotenv from 'dotenv';
dotenv.config();
import connectDB from './db/connect.js';
import cors from 'cors';
import authMiddleware from './middleware/authMiddleware.js';
import authRouter from './routes/authRoutes.js';
import researchRouter from './routes/researchRoutes.js';
import userRouter from './routes/userRoutes.js';
import chatRouter from './routes/chatRoutes.js';
// import for default view
import { dirname } from 'path';
import { fileURLToPath } from 'url';
import path from 'path';
import cookieParser from 'cookie-parser';
const __dirname = dirname(fileURLToPath(import.meta.url));
const app = express();
app.use(cors());
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
const port = process.env.PORT || 5100;
app.use('/api/v1/auth', authRouter);
app.use('/api/v1/research', authMiddleware, researchRouter);
app.use('/api/v1/users', authMiddleware, userRouter);
app.use('/api/v1/chat', authMiddleware, chatRouter);
app.get('/healthz', (req, res) => {
res.status(200).send('OK');
});
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'index.html'));
});
const start = async () => {
try {
await connectDB(process.env.MONGO_URL);
app.listen(port, () => {
console.log(`Server is running on ${port}....`);
});
} catch (error) {
console.log(error);
}
};
start();