-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
53 lines (40 loc) · 1.48 KB
/
Copy pathserver.js
File metadata and controls
53 lines (40 loc) · 1.48 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
41
42
43
44
45
46
47
48
49
50
51
52
53
const express = require('express');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const auth = require('./routes/api/auth');
const tickets = require('./routes/api/tickets')
const admin = require('./routes/api/admin')
const comments = require('./routes/api/comments')
const passport = require('passport');
const cors = require('cors');
const port = process.env.PORT || 8080;
// Config DB
// configure this to test for dev by changing .test.mongoURI or .dev.mongoURI
const db = require('./config/keys').dev.mongoURI;
const app = express();
// Body-parser middleware
app.use(bodyParser.urlencoded({extended:false}));
app.use(bodyParser.json());
app.use(cors());
// Passport middleware
app.use(passport.initialize());
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
// Passport config
require('./config/passport')(passport);
// Connect to MongoDB via Mongoose
mongoose
.connect(db, {useNewUrlParser: true})
.then(() => console.log('MongoDB connected'))
.catch(err => console.log(err));
mongoose.set('useCreateIndex', true);
app.get('/', (req, res) => console.log('Hello World!'));
app.use('/api/auth', auth);
app.use('/api/tickets', tickets);
app.use('/api/admin', admin);
app.use('/api/comments', comments);
app.listen(port, () => console.log(`Server running on port ${port}`));
module.exports = app;