Print Jobs

node v10.24.1
version: 3.4.8
endpointsharetweet
var express = require("@runkit/runkit/express-endpoint/1.0.0"); var bodyParser = require('body-parser') const axios = require("axios") var app = express(exports); // app.use(bodyParser.json()) app.post("/jobs", bodyParser.json(), (req, res) => { console.log(req.headers); console.log(req.body); const resp = { jobReady: false, mediaTypes: [ "application/vnd.star.line", "application/vnd.star.linematrix", "application/vnd.star.starprnt", "application/vnd.star.starprntcore", "text/vnd.star.markup", ], deleteMethod: null, clientAction: null, claimBarcodeReader: null, claimKeyboard: null, display: null, }; // const resp = { // "jobReady": false, // "clientAction": [ // { "request": "GetPollInterval", "options": "" }, // { "request": "PageInfo", "options": "" } // ] // } res.send(resp); }); app.get("/jobs", (req, res) => { console.log("Received GET /jobs request"); let queryUrl = 'https://2009e56ed0cf.ngrok.io/api/printJobs?version=two'; for (const property in req.query) { queryUrl = queryUrl + '&' + property + '=' + req.query[property]; } console.log("Query url built for Docker", queryUrl); const reqBody = { "printData": `[align: centre][font: a]\ [magnify: width 2; height 1] This is a Star Markup Document! [magnify: width 3; height 2]Columns[magnify] [align: left]\ [column: left: Item 1; right: $10.00] [column: left: Item 2; right: $9.95] [column: left: Item 3; right: $103.50] [align: centre]\ [barcode: type qr; data https://www.getnoshspot.com/] [align]\ Thank you for trying the new Star Document Markup Language\ we hope you will find it useful. Please let us know! [cut]` } console.log("Request body built for Docker", reqBody); axios .post(queryUrl, reqBody) .then(function (response) { console.log("res body", response.data); console.log("res headers", response.headers); res.set("content-type", response.headers["content-type"]); res.send(response.data); }) .catch(function (error) { console.log("err in GET /jobs:: ", error); res.send('Failed with error::', error); }); });
Loading…

no comments

    sign in to comment