-
Notifications
You must be signed in to change notification settings - Fork 6
/
app.js
51 lines (42 loc) · 1.36 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
// app.js
// Main entry point for application
const express = require('express');
const mysql = require('mysql');
const path = require('path');
const bodyParser= require('body-parser');
const app = express();
const { getHomePage} = require('./routes/index');
const game = require('./routes/game');
const game_session = require('./routes/game_session');
// TODO: application port should come from config file
const port = 3000;
// TODO: database connection parameters should come from config file
const db = mysql.createConnection({
host: 'localhost',
user: 'app',
password: 'wonderful',
database: 'miechallenge'})
db.connect((err) => {
if (err) {
throw err;
}
console.log('Connected to database');
});
global.db = db;
app.set('port', process.env.port || port);
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.use(bodyParser.urlencoded({ extended: false }));
// If there are static files, make a public directory
app.use(express.static(path.join(__dirname, 'public')));
// Routes
app.get('/', getHomePage);
app.get('/add-game', game.getAdd);
app.post('/add-game', game.postAdd);
app.get('/edit-game/:id', game.getEdit);
app.post('/edit-game/:id', game.postEdit);
app.get('/add-game-session', game_session.getAdd);
app.post('/add-game-session', game_session.postAdd);
app.listen(port, () => {
console.log(`Server running on port: ${port}`);
});