-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
40 lines (31 loc) · 1.09 KB
/
Copy pathserver.js
File metadata and controls
40 lines (31 loc) · 1.09 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
const express = require('express');
const morgan = require('morgan')
const mongoose = require('mongoose');
const cors = require('cors');
const path = require('path')
const app = express();
app.use(cors())
const { authRouter } = require('./controllers/authController');
const { authMiddleware } = require('./middlewares/authMiddleware');
const { userRouter } = require('./controllers/usersController');
app.use(express.json());
app.use(morgan('tiny'));
app.use(express.static(__dirname + '/build'))
app.get('/', function(req, res) {
res.sendFile(path.join(__dirname + '/build/index.html'))
})
app.use('/auth', authRouter);
app.use(authMiddleware);
app.use('/users', userRouter);
const start = async () => {
try {
await mongoose.connect('mongodb+srv://testuser:testpass@cluster0.lpyof.mongodb.net/myFirstDatabase?retryWrites=true&w=majority', {
useNewUrlParser: true, useUnifiedTopology: true
});
// app.listen(process.env.PORT || 5000);
app.listen(5000);
} catch (err) {
console.error(`Error on server startup: ${err.message}`);
}
}
start();