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:
@@ -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!");
|
||||
});
|
||||
|
Reference in New Issue
Block a user