const http = require('http');
const server = http.createServer((req, res) => {
let body = '';
let hasInquiry = false;
let hasPayment = false;
req.on('data', (chunk) => {
body += chunk;
});
req.on('end', () => {
hasInquiry = /<(\w+:)?Inquiry\b/.test(body);
hasPayment = /<(\w+:)?Payment\b/.test(body);
if (req.url === '/dummy-bpjskes' && req.method === 'POST') {
const xmlInquiryResponse = `
BPJSKES
COR
8888890001100299
COR
1
1-H A AZIZ MACHMUD FA
PANGKAL PINANG
4C1E89221DDC2017
0602
13023415
I99
88888900011002990099991058002520260421
2026-04-21 11:13:10
false
00
success
`;
const xmlPaymentResponse = `
0
false
00
success
`;
if (hasInquiry) {
res.writeHead(200, { 'Content-Type': 'text/xml; charset=utf-8' });
res.end(xmlInquiryResponse);
} else if (hasPayment) {
res.writeHead(200, { 'Content-Type': 'text/xml; charset=utf-8' });
res.end(xmlPaymentResponse);
} else {
res.writeHead(400, { 'Content-Type': 'text/plain' });
res.end('Bad Request: No Inquiry or Payment action found');
}
} else {
res.writeHead(404, { 'Content-Type': 'text/plain' });
res.end('Not found');
}
});
});
server.listen(3093, () => {
console.log('SOAP dummy BPJS Kesehatan running at http://localhost:3016/dummy-bpjskes');
});