Compare commits

...

2 Commits

Author SHA1 Message Date
1ddcf1eaf2 Moved metadata route and added static files (robots.txt) 2026-02-11 00:51:24 +01:00
a40a6d6ad8 Added server metadata 2026-02-11 00:32:44 +01:00
4 changed files with 45 additions and 1 deletions

View File

@ -1,2 +1,4 @@
WEB_PORT=3000
IS_PROD=FALSE
IS_PROD=FALSE
INSTANCE_NAME="Azures04"
INSTANCE_LOGO="https://chibieditor.fr/assets/img/avatars/azures.png"

10
routes/index.js Normal file
View File

@ -0,0 +1,10 @@
const express = require("express")
const metaService = require("../services/metaService")
const router = express.Router({ mergeParams: true })
router.get(/.*/, async (req, res, next) => {
const file = metaService.serveStaticFile(req.originalUrl)
return res.status(200).sendFile(file)
})
module.exports = router

9
routes/metadata.js Normal file
View File

@ -0,0 +1,9 @@
const express = require("express")
const router = express.Router()
const metaService = require("../services/metaService")
router.get("/", (req, res) => {
return res.status(200).json(metaService.getServerMetadata())
})
module.exports = router

23
services/metaService.js Normal file
View File

@ -0,0 +1,23 @@
const fs = require("node:fs")
const path = require("node:path")
const { DefaultError } = require("../errors/errors")
function getServerMetadata() {
return {
name: process.env["INSTANCE_NAME"],
logo: process.env["INSTANCE_LOGO"]
}
}
function serveStaticFile(filePath) {
const finalFilePath = path.join(process.cwd(), "data", "static", filePath)
if (fs.existsSync(finalFilePath)) {
return finalFilePath
}
throw new DefaultError(404, "File not found", "File moved/deleted or don't exists", "NotFoundException")
}
module.exports = {
serveStaticFile,
getServerMetadata
}