-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (40 loc) · 1.03 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
38
39
40
41
42
43
44
45
46
47
48
const express = require('express');
const mongoose = require('mongoose');
const dotenv = require('dotenv');
const cors = require('cors');
const cookieParser = require('cookie-parser');
// .env Access
dotenv.config();
// Express Setup + Cors + Cookie Parser
const app = express();
app.use(express.json());
app.use(
cors({
origin: ['http://localhost:3000', 'https://www.myweather.city'],
credentials: true,
allowedHeaders: ['Content-Type', 'Authorization'],
maxAge: 600,
})
);
app.use(cookieParser());
// Port Access
const PORT = process.env.PORT || 5000;
app.listen(PORT, () => console.log(`Server started on port ${PORT}`));
// Testing Initial Connection
app.get('/', (req, res) => {
res.send('Hello World!');
});
// Router Setup
app.use('/auth', require('./routers/userRouter'));
// Connect to MongoDB
mongoose.connect(
process.env.MDB_CONNECT_STRING,
{
useNewUrlParser: true,
useUnifiedTopology: true,
},
(err) => {
if (err) return console.error(err);
console.log('Connected to MongoDB');
}
);