lumpy-turnips/minty

Circular JSON

Closed this issue · 2 comments

Need to fix issue when wrapping output data that contains circular reference.

I created a test case with a simple node app:

'use strict';
const minty = require('minty');
const http = require('http');


const testDoc = `
<html>
  <head>
    <title>Minty Node Example</title>
    <script type="text/javascript">
    var alertContent = 'If this alert shows, you have done a  great job!';

    function showAlert(string) {
      alert(string);
    }
    </script>
  </head>
  <body onload="showAlert(alertContent);">
    <h1>Minty Node Example</h1>
    <p>
      <a onclick="showAlert(alertContent)">Click to show alert again</a>!
    </p>
  </body>
</html>
`;

const testHeader = { 'Content-Type': 'text/plain' }

function sendContent(response, content, header) {
  response.writeHead(200, header);
  response.end(content);
}

var sendMinty = minty.wrap(sendContent);

http.createServer((req, res) => {
  sendMinty(res, testDoc, testHeader);
}).listen(3000);

Error is

/node_modules/minty/lib/run.js:67
  return JSON.stringify(outputObj, (key, value) => {
              ^

TypeError: Converting circular structure to JSON
    at Object.stringify (native)
    at finalizeOutput (/Volumes/Juarez/Users/wade/Code/Codesmith/minty-examples/node_modules/minty/lib/run.js:67:15)
    at /Volumes/Juarez/Users/wade/Code/Codesmith/minty-examples/node_modules/minty/lib/run.js:152:26
    at /Volumes/Juarez/Users/wade/Code/Codesmith/minty-examples/node_modules/minty/index.js:29:22
    at Server.<anonymous> (/Volumes/Juarez/Users/wade/Code/Codesmith/minty-examples/node_example.js:37:3)
    at emitTwo (events.js:100:13)
    at Server.emit (events.js:185:7)
    at HTTPParser.parserOnIncoming [as onIncoming] (_http_server.js:537:12)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:103:23)

This has been fixed and will be uploaded in the next version of minty