-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
38 lines (37 loc) · 1.14 KB
/
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
const express = require('express');
const cors = require('cors');
const dotEnv = require('dotenv');
const mongoose = require('mongoose');
const authRoutes = require('./routes/authRoutes');
const userDataRoutes = require('./routes/userDataRoutes');
dotEnv.config();
const PORT = process.env.PORT;
// const dbURI = 'mongodb://127.0.0.1:27017/item7';
const dbURI =
process.env.NODE_ENV === 'development'
? 'mongodb://127.0.0.1:27017/item7'
: process.env.MONGO_URI;
const app = express();
app.use(express.urlencoded({extended: true}));
app.use(express.json());
app.use(cors());
mongoose
.connect(dbURI, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
useFindAndModify: false,
})
.then(mongo => {
console.log(`mongodb running on ${mongo.connection.host}`);
app.listen(PORT, () => {
console.log(`App listening on port ${PORT}!`);
});
})
.catch(err => console.log("Couldn't connect to MonogoDB", err.message));
app.use('/api/auth', authRoutes);
app.use('/api', userDataRoutes);
app.get('/api/network', (req, res) => res.send({network: true}));
app.get('/', (req, res) => {
res.redirect('https://toyib.vercel.app');
});