feat: add sqlstring and supports-color modules

- Introduced sqlstring module for SQL escape and formatting.
- Added supports-color module to detect terminal color support.
- Created dashboard and login views with Bootstrap styling.
- Implemented user schema in SQL with mock data for testing.
This commit is contained in:
2025-06-20 22:57:32 +02:00
parent b6f72d059d
commit 63d120cc4e
479 changed files with 75965 additions and 11 deletions

View File

@@ -1,8 +1,18 @@
// static variables
const express = require("express");
import express from "express";
const app = express();
const port = 4000;
const path = require("path");
import { loginUser } from "./database.js";
app.use(express.urlencoded({ extended: true }));
app.set("view engine", "ejs");
import path from "path";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
@@ -14,7 +24,33 @@ app.use(express.json());
// Middleware to serve static files from the 'public' directory
app.use(express.static("public"));
// Main code below
// Route to handle GET requests to the root URL
app.get("/", (req, res) => {
res.sendFile(path.join(__dirname, "/public/login.html"));
res.render("login.ejs", { error: null, reload: false });
});
// Route to handle user login
app.post("/login", (req, res) => {
loginUser(req.body.username, req.body.password).then((result) => {
if (result.success) {
res
.status(200)
.render("dashboard.ejs", {
sqlResult: result,
newLink: `/dashboard/${result.user.id}`,
});
} else {
res
.status(401)
.render("login.ejs", { error: result.message, reload: true });
}
});
});
// error handling code
app.use((err, req, res, next) => {
console.error(err.stack);
res.status(500).send("Something broke!");
});