-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
39 lines (34 loc) · 952 Bytes
/
server.js
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 express from 'express';
import { client, connectToMongoDB } from './db.js';
import cors from 'cors';
import apiRouter from './routes/api.js';
import authRouter from './routes/auth.js';
import dotenv from 'dotenv';
dotenv.config();
const app = express();
app.use(
cors({
origin: [
'http://localhost:3000',
'https://blue-protocol-db-test.netlify.app',
],
methods: ['POST', 'PUT', 'GET', 'OPTIONS', 'HEAD'],
credentials: true,
})
);
app.use(express.json());
app.use(express.urlencoded({ extended: false })); // body를 파싱해주기 위해 필요한 미들웨어
async function startServer() {
try {
await connectToMongoDB();
app.listen(process.env.PORT, () => {
console.log('server is running on port: ' + process.env.PORT);
});
} catch (err) {
console.error(err);
}
}
startServer();
app.get('/', async (req, res) => {});
app.use('/api', apiRouter);
app.use('/auth', authRouter);