-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
66 lines (54 loc) · 2.04 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const express = require('express');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const passport = require('passport');
const cors = require('cors');
const dotenv = require('dotenv');
dotenv.config();
const auth = require('./routes/api/auth');
const profile = require('./routes/api/profile');
const question = require('./routes/api/question');
const poll = require('./routes/api/poll');
const answer = require('./routes/api/answer');
const search = require('./routes/api/search');
const suscribe = require('./routes/api/suscribe');
const notification = require('./routes/api/notification');
const category = require('./routes/api/category');
const admin = require('./routes/api/admin');
// const upload = require('./routes/api/upload');
// const notify = require('./functions/Notify');
// triggeredBy, reaction, type, link, triggeredFor questionId
// notify('John Dee', 'Liked', 'Question', 'link/to/notification', 'Dakup Nengak');
const app = express();
// Enable cors middleware
app.use(cors());
// Body parser middleware
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
// DB Config
const db = process.env.localURI;
// Connect to the mongodb
mongoose.connect(process.env.mongoURI || db, { useNewUrlParser: true, useUnifiedTopology: true })
.then(() => console.log("MongoDB Connected"))
.catch((err) => console.log(err));
// Passport Middleware
app.use(passport.initialize());
// Passport Config
require('./config/passport')(passport);
// Use Routes
app.use('/api/auth', auth);
app.use('/api/profile', profile);
app.use('/api/question', question);
app.use('/api/poll', poll);
app.use('/api/answer', answer);
app.use('/api/search', search);
app.use('/api/suscribe', suscribe);
app.use('/api/category', category);
app.use('/api/notification', notification);
app.use('/api/admin', admin);
// app.use('/api/upload', upload);
app.use(express.static('public'));
const port = process.env.PORT || 4000;
app.listen(port, () => {
console.log(`App has Started on port ${port}`);
});