From a7332df80f8dce307d6b271d6e00641903f9066e Mon Sep 17 00:00:00 2001
From: alex <alex@alexloehr.net>
Date: Tue, 12 Aug 2025 13:29:09 +0000
Subject: [PATCH] adding prod
---
app.js | 37 +++++++++++++++++++++++--------------
1 files changed, 23 insertions(+), 14 deletions(-)
diff --git a/app.js b/app.js
index 7e1f278..e7f9dce 100644
--- a/app.js
+++ b/app.js
@@ -1,9 +1,14 @@
const path = require("path")
const fastify = require('fastify')({
- logger: true
+ logger: false,
+ // logger: true
})
const _ = require("lodash")
const fs = require("node:fs")
+const dayjs = require("dayjs")
+
+const log = require("./logger")
+log.info(`--- STARTUP ${dayjs().format("DD.MM.YYYY HH:mm:ss")} ---`)
const db = require("./lib/db")
const libIlias = require("./lib/libIlias")
@@ -19,17 +24,19 @@
// AUTH
fastify.addHook("onRequest", async (req, res) => {
- console.log(req.url)
+ // custom logging
+ log.info(`${req.method} ${req.url}`);
+ // console.log(req.url)
+
const token = req.query.token
- console.log(req.url)
if (token !== settings.authtoken && !req.url.startsWith("/ui/")) {
- console.error("# AUTH ERROR #", token)
+ log.error("# AUTH ERROR #", token)
await promiseDelay(500) // delay response to avoid denial of service attacks
res.code(403)
return res.send({status: "error", error: "access denied"})
}
else {
- console.log("AUTH FOR ", req.url)
+ // log.debug("AUTH FOR ", req.url)
}
})
@@ -40,19 +47,19 @@
searchLib.doIndex().catch(console.error)
fastify
.get("/api/search/user", async function (req, res) {
- console.log(req.query)
+ log.info(req.query)
const search = req.query?.search
if (!search) {
return res.code(422).send({status: "error", msg: "no search"})
}
else {
- console.log(search)
+ log.info(search)
const data = await searchLib.search(search)
return res.send(data)
}
})
.post("/api/search/reindex", async function (req, res) {
- console.log("REINDEX ++++")
+ log.info("REINDEX ++++")
const start = Date.now()
await searchLib.doIndex().catch(console.error)
return res.send({
@@ -97,7 +104,7 @@
})
.get("/api/user/teilnahmen/:userId", async function (req, res) {
let userId = req.params.userId
- console.log(`--------${userId}-----------`, typeof userId)
+ log.debug(`--------${userId}-----------`, typeof userId)
if (!userId || isNaN(Number(userId))) {
return res.code(500).send({status: "error", msg: "userId error"})
}
@@ -127,7 +134,7 @@
}
else {
const res2 = await libIlias.deleteUser(usr_id)
- console.log(res2)
+ log.info(res2)
return res.send(res2)
}
})
@@ -232,7 +239,6 @@
.post("/api/kurs/:refId/status/:usrId", async function (req, res) {
const {refId, usrId} = req.params
const {passed, status} = req.body
- // console.log(88888888888888888888, {refId, usrId, passed, status})
if (!refId || !usrId || _.isNil(passed) || _.isNil(status)) {
throw {
statusCode: 400,
@@ -286,7 +292,7 @@
const indexFile = fs.readFileSync(path.join(__dirname, "vue/dist", 'index.html'), 'utf8')
fastify.setNotFoundHandler(function (req, res) {
- console.log("!!!")
+ log.error("!!! Not found")
// res.sendFile("vue/dist/index.html")
res.type("text/html").send(indexFile)
})
@@ -295,9 +301,11 @@
/////////////////////////////////////////////////////////////////////////
fastify.listen({port: settings.port}, function (err, address) {
- console.log("📡 -=> Listening on", address)
+ console.log(address)
+ log.info(`📡 -=> Listening on ${address}`)
if (err) {
- fastify.log.error(err)
+ // fastify.log.error(err)
+ log.error(err)
process.exit(1)
}
// Server is now listening on ${address}
@@ -308,3 +316,4 @@
async function promiseDelay (ms) {
return new Promise(resolve => setTimeout(resolve, ms))
}
+
--
Gitblit v1.8.0