Untitled

mail@pastecode.io avatar
unknown
plain_text
8 months ago
1.2 kB
5
Indexable
Never
const http = require('http');
const url = require('url');

const server = http.createServer((req, res) => {
  // Parse the request URL to extract query parameters
  const urlParts = url.parse(req.url, true);
  const query = urlParts.query;

  // Check if the "flowName" query parameter is present
  if (query.flowName) {
    const flowNameValue = query.flowName;
    const delayTime = query.delayTime === undefined? 5000 : query.delayTime;
    // Simulate a 5-second delay
    setTimeout(() => {
      // Prepare the JSON response with the "flowName" property
      const responseJSON = { flowName: flowNameValue };

      // Set the response headers
      res.writeHead(200, { 'Content-Type': 'application/json' });

      // Send the JSON response
      res.end(JSON.stringify(responseJSON));
    }, delayTime); // 5-second delay in milliseconds
  } else {
    // If "flowName" is missing, respond with an error message
    res.writeHead(400, { 'Content-Type': 'text/plain' });
    res.end('Error: The "flowName" query parameter is missing.');
  }
});

const port = 1339; // You can change the port if needed
server.listen(port, () => {
  console.log(`Server dalay test is listening on port ${port}`);
});