-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.js
47 lines (38 loc) · 1.34 KB
/
app.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
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
const cors = require('cors');
const mongoose = require('mongoose');
var generateData = require('./generate-data');
var indexRouter = require('./routes/index');
var meetupsRouter = require('./routes/meetups');
var userRouter = require('./routes/users');
var invitationsRouter = require('./routes/invitations');
var scheduleMeetupRouter = require('./routes/scheduleMeetup');
var app = express();
var verifyJWT = require("./middlewares/auth")
mongoose.connect(process.env.MONGODB_URI, {
useNewUrlParser: true,
useUnifiedTopology: true
}).then(() => {
console.log('Connected to MongoDB');
}).catch(err => {
console.log('Error connecting to MongoDB: ', err.message);
});
// Enable Cors
app.use(cors());
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'frontend/build')));
app.use('/', indexRouter);
app.use('/schedule', scheduleMeetupRouter);
app.use('/meetups', verifyJWT, meetupsRouter);
app.use('/users', userRouter);
app.use('/invitations', invitationsRouter);
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'frontend/build/index.html'));
});
module.exports = app;