Files
LupiNex-Connect/servers/gateway/routers/template.router.js
T
2026-06-29 20:14:06 +02:00

30 lines
835 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
! /servers/gateway/routers/template.router.js
*/
// % import nodejs dependencies
const router = require('express').Router();
// % import external dependencies
const rootDir = path.resolve(__dirname, '..', '..', '..');
const { dirs } = require(path.resolve(rootDir, 'configuration', 'mapping.js'));
const { gatewayEvents, sendToWs } = path.resolve(dirs.gateway, 'functions.js');
// $ template router with websocket integration
router.post('/test', (req, res) => {
const correlationId = '';
sendToWs({
type: 'actionName',
correlationId,
data: req.body
});
// ~ wait for callback through central event bus
gatewayEvents.once('ws_message', (msg) => {
if (msg.correlationId === correlationId) res.json(msg.data);
});
});
// § export routers
module.exports = router;