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);
console.log(hasInquiry);
console.log(hasPayment);
console.log(req.url);
console.log(req.method);
if (req.url === '/dummy-ws-mp-7788' && req.method === 'POST') {
const xmlInquiryResponse = `
977887746180906001
Rachmat Sumantri, SH.
501000
0
2018-09-07 17:18:32
0
IDR
PAYMENT OPEN
Panjar Biaya Perkara
PN Jakarta Utara
`;
const xmlPaymentResponse = `
N
00
Sukses
PAYMENT
Mochamad Tabhanie, S.H.
PN Surabaya
`;
if(hasInquiry) {
res.writeHead(200, { 'Content-Type': 'text/xml; charset=ISO-8859-1' });
res.end(xmlInquiryResponse);
} else if (hasPayment) {
res.writeHead(200, { 'Content-Type': 'text/xml; charset=ISO-8859-1' });
res.end(xmlPaymentResponse);
} else {
res.writeHead(404, { 'Content-Type': 'text/plain' });
res.end('Not found');
}
} else {
res.writeHead(404, { 'Content-Type': 'text/plain' });
res.end('Not found');
}
});
});
server.listen(3134, () => {
console.log('SOAP dummy running at http://localhost:3134/dummy-ws-mpp-778');
});