// http://127.0.0.1:8077 import express = require('express'); import cors = require('cors'); import { Server } from 'http'; import { addPrivateNetworkHeader } from '../helpers'; import { sevenLocalPubSubService } from '../localPubSub'; const port = 8077; const app = express(); const state = { cardIn: null, cardReadResponse: {} }; app.use(cors()); app.use(addPrivateNetworkHeader()); app.use(express.json()); app.use(express.urlencoded({ extended: true })); app.get('/read', (req, res) => { res.json(state.cardReadResponse); }); app.post('/write', (req, res) => { state.cardReadResponse = req.body; res.json({ code: 2, description: '', message: 'Write' }); }); app.post('/emulate/read-response', (req, res) => { state.cardReadResponse = req.body.cardReadResponse; res.json({}); }); app.post('/emulate/card-in', (req, res) => { state.cardIn = req.body.publish.data; sevenLocalPubSubService.sendSocketMessage(req.body.publish); res.json({}); }); app.post('/emulate/card-out', (req, res) => { state.cardIn = null; state.cardReadResponse = {}; sevenLocalPubSubService.sendSocketMessage(req.body.publish); res.json({}); }); const emulateCardReader = (): Server => { return app.listen(port); }; export { emulateCardReader };