Skip to content

Commit

Permalink
rewrite entrypoint file
Browse files Browse the repository at this point in the history
  • Loading branch information
kaushik-rishi committed Apr 30, 2024
1 parent 20691d6 commit 0c1a899
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions template/src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function indexEntrypointFile({asyncapi, params}) {
`;

const channelHandlerImports = asyncapi.channels().all().map(channel => {
const channelName = channel.address();
const channelName = channel.id();
return `const ${camelCase(channelName)} = require('./routes/${convertToFilename(channelName)}.js');`;
}).join('\n');

Expand All @@ -46,7 +46,7 @@ export default function indexEntrypointFile({asyncapi, params}) {
`

const channelsMiddleware = asyncapi.channels().all().map(channel => {
const channelName = channel.address();
const channelName = channel.id();
let channelLogic = '';
if (channel.operations().filterByReceive().length > 0) {
channelLogic += `console.log(cyan.bold.inverse(' SUB '), gray('Subscribed to'), yellow('${channelName}'));
Expand Down Expand Up @@ -90,16 +90,11 @@ export default function indexEntrypointFile({asyncapi, params}) {
`;

const handlers = asyncapi.channels().all().map(channel => {
const channelName = channel.address();
let handler = '';
for (let operation of channel.operations()) {
const operationId = operation.id();
if (operation.isReceive())
handler += `${convertOpertionIdToMiddlewareFn(operationId)} : require('./handlers/${convertToFilename(channelName)}').${convertOpertionIdToMiddlewareFn(operationId)},`;
if (operation.isSend())
handler += `${convertOpertionIdToMiddlewareFn(operationId)} : require('./handlers/${convertToFilename(channelName)}').${convertOpertionIdToMiddlewareFn(operationId)},`;
}
return handler;
const channelName = channel.id();
return channel.operations().all().map(operation => {
let operationId = operation.id();
return `${convertOpertionIdToMiddlewareFn(operationId)} : require('./handlers/${convertToFilename(channelName)}').${convertOpertionIdToMiddlewareFn(operationId)}`
}).join(',');
}).join('\n');

return <File name={'index.js'}>
Expand Down

0 comments on commit 0c1a899

Please sign in to comment.