Make database connection
This commit is contained in:
parent
50f4ea890b
commit
c92ecba883
|
@ -1,5 +1,6 @@
|
|||
# Database credentials
|
||||
sql_creds.txt
|
||||
config/config.json
|
||||
|
||||
# Logs
|
||||
logs
|
||||
|
|
|
@ -1,20 +1,64 @@
|
|||
const path = require("path");
|
||||
const express = require("express");
|
||||
const app = express();
|
||||
const port = 3000;
|
||||
const mysql = require("mysql");
|
||||
require("dotenv").config();
|
||||
let connection = mysql.createConnection({
|
||||
host: process.env.DB_HOST,
|
||||
user: process.env.DB_USER,
|
||||
password: process.env.DB_PASSWORD,
|
||||
database: process.env.DB_DATABASE
|
||||
});
|
||||
|
||||
const Match = require("./match.js");
|
||||
|
||||
const app = express();
|
||||
const port = 3000;
|
||||
app.engine('html', require('ejs').renderFile);
|
||||
app.listen(port, () => {
|
||||
console.log(`Listening on port ${port}`)
|
||||
})
|
||||
|
||||
|
||||
app.get("/", (req, res) => {
|
||||
res.sendFile(path.join(__dirname, "public", "index.html"));
|
||||
res.sendFile(path.join(__dirname, "public", "landing.html"));
|
||||
});
|
||||
|
||||
app.get("/getMatches", (req, res) => {
|
||||
connection.query("SELECT * FROM matches", (err, matches) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
} else {
|
||||
res.send(matches);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
app.get("/match", (req, res) => {
|
||||
let match = new Match(1, [1, 2]);
|
||||
res.send(JSON.stringify(match));
|
||||
let tournaments = {
|
||||
"1": {
|
||||
"name": "Tournament 1",
|
||||
"description": "This is the first tournament",
|
||||
"matches":[
|
||||
{"id": "2",
|
||||
"player1": "Player 1",
|
||||
"player2": "Player 2",
|
||||
"winner": "Player 1",
|
||||
}
|
||||
]
|
||||
},
|
||||
"2": {
|
||||
"name": "Tournament 2",
|
||||
"description": "This is the second tournament",
|
||||
"matches":[
|
||||
{"id": "2",
|
||||
"player1": "Player 1",
|
||||
"player2": "Player 2",
|
||||
"winner": "Player 1",
|
||||
}]
|
||||
}
|
||||
};
|
||||
app.get("/tournament/:tournamentId", (req, res) => {
|
||||
res.render(path.join(__dirname, "public", "tournament.html"), {"tournament":tournaments[req.params.tournamentId]});
|
||||
});
|
||||
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -10,7 +10,11 @@
|
|||
"author": "felixalb, kristoju, jonajha, krisleri",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"express": "^4.17.3"
|
||||
"dotenv": "^16.0.0",
|
||||
"ejs": "^3.1.6",
|
||||
"express": "^4.17.3",
|
||||
"mysql": "^2.18.1",
|
||||
"sequelize": "^6.17.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nodemon": "^2.0.15"
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Tournament</h1>
|
||||
<div id="output"></div>
|
||||
<script>
|
||||
window.TOURNAMENT = JSON.parse('<%- JSON.stringify(tournament) %>');
|
||||
document.getElementById("output").innerHTML = JSON.stringify(TOURNAMENT);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue