-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
37 lines (34 loc) · 1.08 KB
/
index.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
const express = require('express');
const mongoose = require('mongoose');
const snippetRoutes = require('./routes/snippet');
const userRoutes = require('./routes/user');
const dotenv = require('dotenv');
const cors = require('cors');
const morgan = require('morgan');
const cookieParser = require('cookie-parser');
dotenv.config();
const app = express();
app.use(express.json());
app.use(morgan('dev'));
app.use(
cors({
origin: [
'http://localhost:3000',
'https://snippetmanager-datumbrain.netlify.app',
],
credentials: true,
})
);
app.use(cookieParser());
app.use('/snippet', snippetRoutes);
app.use('/auth', userRoutes);
mongoose.connect(
`mongodb+srv://${process.env.DB_USER}:${process.env.DB_PASSWORD}@snippet-manager.cnbee.mongodb.net/${process.env.DB_NAME}?retryWrites=true&w=majority`,
{ useNewUrlParser: true, useUnifiedTopology: true },
(error) => {
if (error) return console.log({ error });
console.log('Connected to MongoDB');
}
);
const PORT = process.env.PORT || 5000;
app.listen(PORT, () => console.log(`Started server on port ${PORT}.`));