UNPKG

roach-storm

Version:

Apache Kafka to Google Pub/Sub Gateway, API controlled

44 lines (43 loc) 1.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const express = require("express"); const routeProduce = (roachStorm) => { const router = express.Router(); const messageHandler = roachStorm.messageHandler; router.get("/", (req, res) => { res.json({ parent: "/api", self: "/api/produce", children: [ "/api/produce/kafka-batch", ], }); }); router.post("/kafka-batch", async (req, res) => { if (!res.locals.access.topicConfigAccessAllowedForRequest(req)) { res.status(403).json({ error: "Access not allowed", }); return; } if (!req.body || !req.body.batch || typeof req.body.batch !== "object") { res.status(400).json({ error: "Body should be a valid object containing " + "SortedMessageBatch, { batch: { topic: { partition: [ { key, value: { .. } } ] } } }", }); return; } try { const sortedMessageBatch = req.body.batch; const results = await messageHandler.handleSortedMessageBatch(sortedMessageBatch); res.status(201).json(results); } catch (error) { res.status(500).json({ error: "An error occured " + error.message, }); } }); return router; }; exports.routeProduce = routeProduce;