-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
73 lines (61 loc) · 2.11 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const express = require('express');
const path = require('path');
const session = require('express-session');
var bodyParser = require('body-parser');
const app = express();
const mysql = require('mysql');
let port = process.env.PORT || 3000;
// Router Setup
let indexRouter = require('./routes/index');
let errorRouter = require('./routes/error');
let loginRouter = require('./routes/login');
let accountRouter = require('./routes/account');
let userRouter = require('./routes/user');
let createPostRouter = require('./routes/createPost');
let registerRouter = require('./routes/register');
let landingPageRouter = require('./routes/landingPage');
let logoutRouter = require('./routes/logout');
app.use(express.static('public'));
app.use(express.static(__dirname + '/public'));
app.use(bodyParser.urlencoded({ extended: true }));
app.use( session ({ secret: "Gimme some Cheese", resave: true, saveUninitialized: true }));
// View engine set up
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(bodyParser.urlencoded({extended: true}));
app.use('/', indexRouter);
app.use('/login', loginRouter);
app.use('/account', accountRouter);
app.use('/user', userRouter);
app.use('/createPost', createPostRouter);
app.use('/register', registerRouter);
app.use('/landingPage', landingPageRouter);
app.use('/logout', logoutRouter);
app.use('*', errorRouter);
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
});
function dbConnection() {
let conn = mysql.createConnection({
host: 'ko86t9azcob3a2f9.cbetxkdyhwsb.us-east-1.rds.amazonaws.com',
user: 'hpwto3xsc5rizajc',
password: 'hvawdewg5btdb737',
database: 'g3qs1bndvu07j9c5'
})
return conn;
};
// function isAuthenticated(req, res, next){
// if(!req.session.authenticated) res.redirect('/login');
// else next();
// }
let db = dbConnection();
db.connect((err) => {
if(err) {
console.log('error has occurred');
throw err;
}
console.log('Connected to database');
});
global.db = db;
// global.isAuthenticated = isAuthenticated;
module.exports = app;