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)
@@ -85,6 +93,16 @@
         return res.code(404).send({status: "error", msg: "not found"})
      }
   })
   .get("/kurs/:refId", async function (req, res) {
      const {refId} = req.params
      let data = await db.getKurs(refId)
      if (data) {
         return res.send(data)
      }
      else {
         return res.code(404).send({status: "error", msg: "not found"})
      }
   })
   .get("/kurs/items/:refId", async function (req, res) {
      const {refId} = req.params
      let data = await db.getKursItems(refId)