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C;IArCD,uBAqCC","sourcesContent":["import { RequestHandler } from 'express';\n\nimport { Context } from '../Server';\nimport { Message } from '../channels/Base';\n\nexport default function post(context: Context): RequestHandler {\n return (request, response, next) => {\n if (request.method !== 'POST') {\n return next();\n }\n\n const { executor, handleMessage } = context;\n\n try {\n let rawMessages: any = request.body;\n\n if (!Array.isArray(rawMessages)) {\n rawMessages = [rawMessages];\n }\n\n const messages: Message[] = rawMessages.map(function(\n messageString: string\n ) {\n return JSON.parse(messageString);\n });\n\n executor.log('Received HTTP messages');\n\n Promise.all(messages.map(message => handleMessage(message)))\n .then(() => {\n response.statusCode = 204;\n response.end();\n })\n .catch(() => {\n response.statusCode = 500;\n response.end();\n });\n } catch (_) {\n response.statusCode = 500;\n response.end();\n }\n };\n}\n"]} |