-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
63 lines (52 loc) · 1.95 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
require('dotenv').config()
const express = require("express");
const bodyParser = require("body-parser");
const methodOverride = require("method-override");
const mongoose = require('mongoose');
const dbConfig = require('./config/database.config');
const UserRoute = require('./routes/UserRoutes');
const ForumRoute = require('./routes/ForumRoutes');
const BlogRoute = require('./routes/BlogRoutes');
const GoogleRoute = require('./routes/GoogleRoutes')
const cookieParser = require("cookie-parser");
const session = require('express-session');
const passport = require('passport');
const {isLoggedIn, isAuth} = require('./middlewares/authMiddleware');
const flash = require('express-flash');
const swaggerUi = require('swagger-ui-express');
swaggerDocument = require('./swagger.json');
const app = express();
const port = process.env.PORT || 3000;
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument))
app.use(bodyParser.urlencoded({extended: false}))
app.use(bodyParser.json())
app.set('view engine', 'ejs');
app.use(express.static("public"));
mongoose.Promise = global.Promise;
mongoose.connect(dbConfig.url, {
useNewUrlParser: true
}).then(() => {
console.log("Database Connected Successfully!");
}).catch(err => {
console.log('Could not connect to the database', err);
process.exit();
});
app.use(cookieParser());
app.use(methodOverride('_method'));
app.use(flash())
app.use(session({
secret: process.env.SECRET,
resave: false,
saveUninitialized: false,
}))
app.use(passport.initialize())
app.use(passport.session())
app.use("/", require("./routes/root"));
app.use("/signup", isAuth, require("./routes/signup"));
app.use("/signing", isAuth, require("./routes/signing"))
app.use("/account", isLoggedIn, require("./routes/myaccount"))
app.use('/users', UserRoute);
app.use('/forums', ForumRoute);
app.use('/blogs', BlogRoute);
app.use('/auth', GoogleRoute);
app.listen(port, () => console.log(`App listening at http://localhost:${port}`))