-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
64 lines (56 loc) · 1.81 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
const compression = require('compression');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var mysql = require('mysql2');
var session = require('express-session');
var indexRouter = require('./routes/index');
var clubsRouter = require('./routes/clubs');
var adminRouter = require('./routes/admin');
var apiRouter = require('./routes/api/api');
var apiUsersRouter = require('./routes/api/users');
var apiClubsRouter = require('./routes/api/clubs');
var apiEventsRouter = require('./routes/api/events');
var apiUpdatesRouter = require('./routes/api/updates');
var app = express();
app.use(compression())
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(session({
secret: "Session",
resave: false,
saveUninitialized: true,
cookie: { secure: false }
}));
var dbConnectionPool = mysql.createPool({
host: process.env.RDS_HOSTNAME,
port: process.env.RDS_PORT,
user: process.env.RDS_USERNAME,
password: process.env.RDS_PASSWORD,
database: process.env.RDS_DB_NAME,
});
app.use(function (req, res, next) {
req.pool = dbConnectionPool;
next();
});
// to use res.render(html file)
app.use(express.static(path.join(__dirname, 'public'), {
dotfiles: 'ignore',
index: 'Home/home.html'
}));
app.set('views', path.join(__dirname, 'public'));
app.engine('html', require('ejs').renderFile);
app.set('view engine', 'ejs');
// routers
app.use('/', indexRouter);
app.use('/clubs', clubsRouter);
app.use('/admin', adminRouter);
app.use('/api', apiRouter);
app.use('/api/clubs', apiClubsRouter);
app.use('/api/users', apiUsersRouter);
app.use('/api/events', apiEventsRouter);
app.use('/api/updates', apiUpdatesRouter);
module.exports = app;