const fs = require("fs"); const express = require("express"); const app = express(); const { exec } = require("child_process"); const nodeMailer = require("nodemailer"); // Read configuration file const contentFile = fs.readFileSync("./service_run/giteaService.conf", "utf8"); let checkStatus = "ready"; // Get port from configuration file const PORT = contentFile .split("\n") .find(line => line.includes("PORT_SERVICE")) ?.split("=")[1] .trim() || 5000; // Get email configuration from config file const getConfigValue = (key) => contentFile .split("\n") .find(line => line.includes(key)) ?.split("=")[1] .trim(); // Configure email transporter const createTransporter = () => nodeMailer.createTransport({ pool: true, host: getConfigValue("EMAIL_HOST") || "smtp.gmail.com", port: parseInt(getConfigValue("EMAIL_PORT") || "587"), secure: getConfigValue("EMAIL_SECURE") === "True", auth: { user: getConfigValue("EMAIL_USER") || "git@notification.com", pass: getConfigValue("EMAIL_PASSWORD") || "123456789", }, }); app.use(express.json()); app.post("/git/gitea-webhook", async (req, res) => { let title = ""; const checkSendMail = getConfigValue("SEND_EMAIL"); const emailAddress = getConfigValue("RECEIVE_EMAIL_ADDRESS"); const emailFrom = getConfigValue("EMAIL_FROM") || "git@notification.com"; const giteaEvent = req.headers["x-gitea-event"]; // Return response immediately res.status(200).send({ mess: "The event has been received!", data: req.body }); console.log("STATUS:", checkStatus); // Check if there is a running process if (checkStatus === "busy") { if (checkSendMail === "True") { const transporter = createTransporter(); const options = { from: emailFrom, to: emailAddress, subject: "Git notifications (Fail)", html: "