added api server and changed docker files
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
||||
} from "../shared/database.js";
|
||||
import dotenv from "dotenv";
|
||||
import path from "path";
|
||||
import axios from "axios";
|
||||
import { fileURLToPath } from "url";
|
||||
const app = express();
|
||||
dotenv.config();
|
||||
@@ -33,17 +34,26 @@ app.get("/", (req, res) => {
|
||||
});
|
||||
|
||||
app.post("/login", (req, res) => {
|
||||
loginUser(req.body.username, req.body.password).then((result) => {
|
||||
if (result.success) {
|
||||
// On successful login, render the dashboard and update latestUser
|
||||
res.status(200).render("userView.ejs");
|
||||
} else {
|
||||
// On failure, re-render login page with error message
|
||||
const { username, password } = req.body;
|
||||
const apiUrl = "http://localhost:4002/login";
|
||||
|
||||
axios
|
||||
.post(apiUrl, { username, password })
|
||||
.then(function (response) {
|
||||
if (response.data.loginQuery) {
|
||||
// If login is successful, redirect to the dashboard
|
||||
res.render("userView.ejs");
|
||||
} else {
|
||||
// If login fails, render the login page with an error message
|
||||
res.status(404).render("index.ejs", { error: response.data.message });
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.error("Error during login:", error);
|
||||
res
|
||||
.status(401)
|
||||
.render("index.ejs", { error: result.message, });
|
||||
}
|
||||
});
|
||||
.status(500)
|
||||
.render("index.ejs", { error: "An error occurred during login." });
|
||||
});
|
||||
});
|
||||
|
||||
// error handling code
|
||||
|
Reference in New Issue
Block a user