REST Service for POPCORN - ILIAS
alex
2025-06-02 21982a1d077140d85262a8c5b7c5e314ed48b9eb
app.js
@@ -1,3 +1,4 @@
const path = require("path")
const fastify = require('fastify')({
   logger: true
})
@@ -8,10 +9,17 @@
/////////////////////////////////////////////////////////////////////////
fastify.register(require('@fastify/static'), {
   root: path.join(__dirname, 'vue/dist'),
   prefix: '/ui/', // optional: default '/'
   // constraints: { host: 'example.com' } // optional: default {}
})
// AUTH
fastify.addHook("onRequest", async (req, res) => {
   console.log(req.url)
   const token = req.query.token
   if (token !== settings.authtoken) {
   if (token !== settings.authtoken && !req.url.startsWith("/ui/")) {
      console.error("# AUTH ERROR #", token)
      await promiseDelay(500) // delay response to avoid denial of service attacks
      res.code(403)