1 | (function (factory) {
|
2 | if (typeof module === "object" && typeof module.exports === "object") {
|
3 | var v = factory(require, exports);
|
4 | if (v !== undefined) module.exports = v;
|
5 | }
|
6 | else if (typeof define === "function" && define.amd) {
|
7 | define(["require", "exports"], factory);
|
8 | }
|
9 | })(function (require, exports) {
|
10 | "use strict";
|
11 | Object.defineProperty(exports, "__esModule", { value: true });
|
12 | function post(context) {
|
13 | return function (request, response, next) {
|
14 | if (request.method !== 'POST') {
|
15 | return next();
|
16 | }
|
17 | var executor = context.executor, handleMessage = context.handleMessage;
|
18 | try {
|
19 | var rawMessages = request.body;
|
20 | if (!Array.isArray(rawMessages)) {
|
21 | rawMessages = [rawMessages];
|
22 | }
|
23 | var messages = rawMessages.map(function (messageString) {
|
24 | return JSON.parse(messageString);
|
25 | });
|
26 | executor.log('Received HTTP messages');
|
27 | Promise.all(messages.map(function (message) { return handleMessage(message); }))
|
28 | .then(function () {
|
29 | response.statusCode = 204;
|
30 | response.end();
|
31 | })
|
32 | .catch(function () {
|
33 | response.statusCode = 500;
|
34 | response.end();
|
35 | });
|
36 | }
|
37 | catch (_) {
|
38 | response.statusCode = 500;
|
39 | response.end();
|
40 | }
|
41 | };
|
42 | }
|
43 | exports.default = post;
|
44 | });
|
45 |
|
\ | No newline at end of file |