Created the click action

This commit is contained in:
2022-12-27 15:06:46 +01:00
parent fa7dd5a352
commit c6388cf942

23
server/actions/click.js Normal file
View File

@ -0,0 +1,23 @@
const {getLinkByAccess, clickLink} = require("../controller/link");
const {getModule} = require("../controller/module");
const app = require('express').Router();
const sendNotFound = (res) => res.status(404).render(process.cwd() + "/server/templates/404");
app.get("/", async (req, res) => {
res.locals.accessId = req.baseUrl.substring(1, req.baseUrl.length) || "home";
const currentDomain = req.get('host')?.split(":")[0] || "localhost";
const link = await getLinkByAccess(res.locals.accessId, currentDomain);
if (!link) return sendNotFound(res);
const module = getModule(link.type);
if (!module) return sendNotFound(res);
await clickLink(link.accessId, link.domainName);
res.locals.meta = JSON.parse(link.meta);
module.onClick(link.id, link.accessId, JSON.parse(link.meta), res);
});
module.exports = app;