-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
71 lines (59 loc) · 2.6 KB
/
index.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
67
68
69
70
71
const expressEdge = require("express-edge");
const express = require("express");
const edge = require("edge.js");
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
const fileUpload = require("express-fileupload");
const expressSession = require('express-session');
const connectMongo = require('connect-mongo');
const auth = require("./middleware/auth");
const redirectIfAuthenticated = require('./middleware/redirectIfAuthenticated')
const connectFlash = require("connect-flash");
const storePost = require('./middleware/storePost')
const createPostController = require('./controllers/createPost');
const homePageController = require('./controllers/homePage');
const storePostController = require('./controllers/storePost');
const getPostController = require('./controllers/getPost');
const createUserController = require("./controllers/createUser");
const storeUserController = require('./controllers/storeUser');
const loginController = require("./controllers/login");
const loginUserController = require('./controllers/loginUser');
const app = new express();
mongoose.connect('mongodb+srv://antonio:[email protected]/techblog?authSource=admin&replicaSet=Cluster0-shard-0&w=majority&readPreference=primary&appname=MongoDB%20Compass%20Community&retryWrites=true&ssl=true', { useNewUrlParser: true })
.then(() => 'You are now connected to Mongo!')
.catch(err => console.error('Something went wrong', err))
const mongoStore = connectMongo(expressSession);
var favicon = require('serve-favicon');
app.use(favicon(__dirname + '/public/img/favicon.png'));
app.use(expressSession({
secret: 'secret',
store: new mongoStore({
mongooseConnection: mongoose.connection
})
}));
app.use(connectFlash());
app.use(fileUpload());
app.use(express.static('public'));
app.use(expressEdge.engine);
app.set('views', __dirname + '/views');
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({
extended: true
}));
app.use('*', (req, res, next) => {
edge.global('auth', req.session.userId)
next()
});
app.get("/", homePageController);
app.get("/createPost", createPostController);
app.use('/postsimage', storePost);
app.get('/login', loginController);
app.post('/usersLogin', loginUserController);
app.get("/createUser", createUserController);
app.get("/:id", getPostController);
app.post("/postsimage", storePostController);
app.post("/usersReg", storeUserController);
app.get("/new", createPostController);
app.listen(4000, () => {
console.log('App listening on port 4000')
});