635a130f0b
Build and Push Docker Images / detect-changes (push) Successful in 11s
Build and Push Docker Images / build-auth-api (push) Successful in 1m0s
Build and Push Docker Images / build-employee-api (push) Successful in 1m2s
Build and Push Docker Images / build-transit-api (push) Successful in 1m1s
Build and Push Docker Images / build-error-log-api (push) Successful in 1m5s
Build and Push Docker Images / build-admin-ui (push) Successful in 1m13s
Build and Push Docker Images / build-monitoring-ui (push) Successful in 1m15s
Build and Push Docker Images / deploy-test-node (push) Successful in 3s
### Summary of Changes
1. Documentation Consolidation:
• Relocated the docs/ folder and all repository .md files (README.md, DEPLOYMENT.md, DOCKER_README.md,
DOMAINS_README.md, GETTING_STARTED.md, CI_CD_PORTAINER_GUIDE.md, ADMIN_DEPLOYMENT_SUMMARY.md,
SECURITY_PRIVATE_FILES.md, handoff.md, azure-project-plan.md, plus service-specific READMEs) into .
• Updated document links in README.md.
2. AI Agent Project Map:
• Created PROJECT_MAP.md in the project root containing complete architecture diagrams, service specs, ports, DB
schemas, environment variables, and developer workflows.
• Added PROJECT_MAP.md to .gitignore.
3. Monitoring UI & Infrastructure Integration:
• Added monitoring_ui service to docker-compose.yml (port 5175).
• Configured Gitea workflow docker-build.yml for monitoring_ui builds.
• Added CORS middleware headers in index.js.
• Added nginx.conf copy step in Dockerfile.
──────
### Recommended Commit Message
docs: consolidate project documentation into monitoring_ui and add agent project map
- Move all markdown documentation files and docs/ folder into monitoring_ui/docs/
- Update documentation hub index (monitoring_ui/docs/README.md) with relative paths
- Generate comprehensive AI agent reference map (PROJECT_MAP.md) in repository root
- Add PROJECT_MAP.md and monitoring_ui build output/env overrides to .gitignore
- Integrate monitoring_ui service into docker-compose.yml and Gitea CI workflow
- Configure CORS handling in employee_api for monitoring dashboard access
──────
### Alternative Short Commit Message
refactor(docs): move docs to monitoring_ui and create AI agent PROJECT_MAP.md
113 lines
3.5 KiB
JavaScript
113 lines
3.5 KiB
JavaScript
const express = require("express");
|
|
const bcrypt = require("bcryptjs");
|
|
const db = require("./db");
|
|
require("dotenv").config();
|
|
|
|
const app = express();
|
|
app.use(express.json());
|
|
|
|
app.use((req, res, next) => {
|
|
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
res.setHeader("Access-Control-Allow-Methods", "GET,POST,OPTIONS");
|
|
res.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization");
|
|
if (req.method === "OPTIONS") return res.sendStatus(204);
|
|
next();
|
|
});
|
|
|
|
const ERROR_LOG_API_URL =
|
|
process.env.ERROR_LOG_API_URL ||
|
|
"https://error.xtransit.testinstance.nl/error_log";
|
|
|
|
function friendlyErrorMessage(statusCode) {
|
|
if (statusCode === 400) return "Controleer je invoer en probeer opnieuw.";
|
|
if (statusCode === 401) return "Je sessie is verlopen. Log opnieuw in.";
|
|
if (statusCode === 403) return "Je hebt hier geen toegang toe.";
|
|
if (statusCode === 404) return "Niet gevonden.";
|
|
return "Er ging iets mis. Probeer het later opnieuw.";
|
|
}
|
|
|
|
async function reportError({ partofservice, error }) {
|
|
try {
|
|
await fetch(ERROR_LOG_API_URL, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({
|
|
service: "employee_api",
|
|
partofservice,
|
|
error,
|
|
}),
|
|
});
|
|
} catch (_) {}
|
|
}
|
|
|
|
app.use((req, res, next) => {
|
|
const originalJson = res.json.bind(res);
|
|
res.json = (body) => {
|
|
if (res.statusCode >= 400 && body && typeof body === "object") {
|
|
const rawError =
|
|
body.error || body.message || body.details || `HTTP ${res.statusCode}`;
|
|
void reportError({
|
|
partofservice: `${req.method} ${req.originalUrl}`,
|
|
error: rawError,
|
|
});
|
|
return originalJson({ error: friendlyErrorMessage(res.statusCode) });
|
|
}
|
|
return originalJson(body);
|
|
};
|
|
|
|
next();
|
|
});
|
|
|
|
// Employee onboarding
|
|
app.post("/createemployee", async (req, res) => {
|
|
try {
|
|
const { firstname, lastname, job, password } = req.body;
|
|
if (!firstname || !lastname || !job || !password)
|
|
return res.status(400).json({
|
|
error: "Firstname, Lastname, Job title and password are required",
|
|
});
|
|
|
|
const resultCreateEmployee = await db.query(
|
|
"INSERT INTO workers.employees (firstname, lastname, job) VALUES ($1, $2, $3) RETURNING id",
|
|
[firstname, lastname, job],
|
|
);
|
|
const newEmployee = resultCreateEmployee.rows[0];
|
|
const encryptedpassword = await bcrypt.hash(password, 12);
|
|
const resultCreateUser = await db.query(
|
|
"INSERT INTO workers.users (employee, password) VALUES ($1, $2) RETURNING usercode",
|
|
[newEmployee.id, encryptedpassword],
|
|
);
|
|
const newUser = resultCreateUser.rows[0];
|
|
return res
|
|
.status(201)
|
|
.json({ employee: firstname, code: newUser.usercoden });
|
|
} catch (err) {
|
|
void reportError({
|
|
partofservice: `${req.method} ${req.originalUrl}`,
|
|
error: err?.stack || err?.message || String(err),
|
|
});
|
|
console.error(err);
|
|
res.status(500).json({ error: friendlyErrorMessage(500) });
|
|
}
|
|
});
|
|
|
|
app.get("/health", async (_req, res, _next) => {
|
|
try {
|
|
return res.status(200).json({ endpoint: "reachable" });
|
|
} catch (err) {
|
|
void reportError({
|
|
partofservice: `${req.method} ${req.originalUrl}`,
|
|
error: err?.stack || err?.message || String(err),
|
|
});
|
|
console.error(err);
|
|
res
|
|
.status(500)
|
|
.json({ endpoint: "unreachable", error: friendlyErrorMessage(500) });
|
|
}
|
|
});
|
|
|
|
const PORT = process.env.PORT || 4000;
|
|
app.listen(PORT, () => console.log(`Auth API listening on ${PORT}`));
|
|
|
|
module.exports = app;
|