Merge pull request 'index: increase font of critter name' (#9) from font-size into main
Basic Checking / Explore-Gitea-Actions (push) Successful in 32s Details

Reviewed-on: #9
This commit is contained in:
Vincent Batts 2023-09-28 18:23:43 +00:00
commit 3cc7a378c0
3 changed files with 22 additions and 14 deletions

25
app.js
View File

@ -4,15 +4,18 @@ const path = require("path");
const morgan = require("morgan"); const morgan = require("morgan");
const bodyParser = require("body-parser"); const bodyParser = require("body-parser");
const sqlite3 = require("sqlite3").verbose(); const sqlite3 = require("sqlite3").verbose();
const bole = require('bole');
const log = bole('app');
const config = require('./config');
const app = express(); const app = express();
// Create an SQLite database and initialize tables // Create an SQLite database and initialize tables
const db = new sqlite3.Database("db/results.db", (err) => { const db = new sqlite3.Database(config.db_path, (err) => {
if (err) { if (err) {
console.error("Error opening SQLite database:", err.message); log.error("Error opening SQLite database:", err.message);
} else { } else {
console.log("Connected to SQLite database"); log.info("Connected to SQLite database", config.db_path);
db.run(` db.run(`
CREATE TABLE IF NOT EXISTS button_clicks ( CREATE TABLE IF NOT EXISTS button_clicks (
id INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER PRIMARY KEY AUTOINCREMENT,
@ -59,16 +62,16 @@ try {
[animal, animal], [animal, animal],
(err) => { (err) => {
if (err) { if (err) {
console.error(`Error inserting animal ${animal}: `, err.message); log.error(`Error inserting animal ${animal}: `, err.message);
} else { } else {
console.log(`Success inserting animal ${animal}`); log.info(`Success inserting animal ${animal}`);
} }
}, },
); );
} }
}); });
} catch (error) { } catch (error) {
console.error("Error loading animals:", error); log.error("Error loading animals:", error);
animals = ["Dog", "Cat", "Elephant", "Lion", "Giraffe"]; animals = ["Dog", "Cat", "Elephant", "Lion", "Giraffe"];
} }
@ -88,7 +91,7 @@ app.get("/getNextAnimal", async (req, res) => {
const randomAnimal = animals[randomIndex]; const randomAnimal = animals[randomIndex];
res.json({ animalName: randomAnimal }); res.json({ animalName: randomAnimal });
} catch (error) { } catch (error) {
console.error("Error fetching random animal:", error); log.error("Error fetching random animal:", error);
res.status(500).json({ error: "Internal server error" }); res.status(500).json({ error: "Internal server error" });
} }
}); });
@ -98,7 +101,7 @@ app.post("/recordButtonClick", (req, res) => {
try { try {
//const { buttonName, sessionId } = req.body; //const { buttonName, sessionId } = req.body;
const result = req.body; const result = req.body;
console.error(result); log.error(result);
db.run( db.run(
"INSERT INTO button_clicks (session_id, animal_name, button_name, timestamp, time_difference) VALUES (?, ?, ?, ?, ?)", "INSERT INTO button_clicks (session_id, animal_name, button_name, timestamp, time_difference) VALUES (?, ?, ?, ?, ?)",
@ -111,7 +114,7 @@ app.post("/recordButtonClick", (req, res) => {
], ],
(err) => { (err) => {
if (err) { if (err) {
console.error("Error recording button click:", err.message); log.error("Error recording button click:", err.message);
res.status(500).json({ error: "Internal server error" }); res.status(500).json({ error: "Internal server error" });
} else { } else {
res.sendStatus(200); res.sendStatus(200);
@ -119,7 +122,7 @@ app.post("/recordButtonClick", (req, res) => {
}, },
); );
} catch (error) { } catch (error) {
console.error("Error recording button click:", error); log.error("Error recording button click:", error);
res.status(500).json({ error: "Internal server error" }); res.status(500).json({ error: "Internal server error" });
} }
}); });
@ -200,7 +203,7 @@ app.get("/results", async (req, res) => {
await Promise.all([getCount, getTotalAvgTime, getAvgTime]); await Promise.all([getCount, getTotalAvgTime, getAvgTime]);
res.json(results); res.json(results);
} catch (error) { } catch (error) {
console.error("Error fetching results:", error); log.error("Error fetching results:", error);
res.status(500).json({ error: "Internal server error" }); res.status(500).json({ error: "Internal server error" });
} }
}); });

View File

@ -9,7 +9,9 @@ config.express = {
if (PRODUCTION) { if (PRODUCTION) {
config.express.ip = '0.0.0.0'; config.express.ip = '0.0.0.0';
bole.output({ level: 'debug', stream: process.stdout }) config.db_path = "db/results.db";
} else {
bole.output({ level: 'info', stream: process.stdout }) bole.output({ level: 'info', stream: process.stdout })
} else {
config.db_path = ":memory:";
bole.output({ level: 'debug', stream: process.stdout })
} }

View File

@ -6,7 +6,7 @@
</head> </head>
<body> <body>
<div id="isCritter"> <div id="isCritter">
<h1>Is this a Critter?</h1> <h3>Is this a Critter?</h3>
<p id="animal-name">what about?:</p> <p id="animal-name">what about?:</p>
<button id="isCritterButton">Is Critter</button> <button id="isCritterButton">Is Critter</button>
<button id="isNotCritterButton">Is <b>not</b> Critter</button> <button id="isNotCritterButton">Is <b>not</b> Critter</button>
@ -23,6 +23,9 @@
</div> </div>
<script src="/asset/frontend.js"></script> <script src="/asset/frontend.js"></script>
<style type="text/css"> <style type="text/css">
#animal-name {
font-size: 25px;
}
#isCritter { #isCritter {
text-align: center; text-align: center;
} }