Created the click action
This commit is contained in:
23
server/actions/click.js
Normal file
23
server/actions/click.js
Normal 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;
|
Reference in New Issue
Block a user