Created
December 24, 2024 11:46
-
-
Save chamilaadhi/7d746ab6f23726526df5aaa1f14616dd to your computer and use it in GitHub Desktop.
xml-backend.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const http = require('http'); | |
| const port = 3011; | |
| // Create an HTTP server | |
| const server = http.createServer((req, res) => { | |
| if (req.url === '/metrics/summary' && req.method === 'GET') { | |
| // Define the XML response content | |
| const xmlResponse = `<?xml version="1.0" encoding="UTF-8"?> | |
| <metrics> | |
| <summary> | |
| <total>42</total> | |
| <confirmed>35</confirmed> | |
| <pending>7</pending> | |
| </summary> | |
| </metrics>`; | |
| // Set the response headers to indicate XML content | |
| res.writeHead(200, { 'Content-Type': 'application/xml' }); | |
| // Send the XML response | |
| res.end(xmlResponse); | |
| } else { | |
| // Handle 404 for other routes | |
| res.writeHead(404, { 'Content-Type': 'text/plain' }); | |
| res.end('Not Found'); | |
| } | |
| }); | |
| // Start the server | |
| server.listen(port, () => { | |
| console.log(`Server is running at http://localhost:${port}`); | |
| }); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment