Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RangeError: Maximum call stack size exceeded #46

Open
OleileiA opened this issue Oct 11, 2017 · 3 comments
Open

RangeError: Maximum call stack size exceeded #46

OleileiA opened this issue Oct 11, 2017 · 3 comments
Labels

Comments

@OleileiA
Copy link

OleileiA commented Oct 11, 2017

my code is simple:

const nodeMonkey = require('node-monkey');
const Koa = require('koa');
nodeMonkey();
const app = new Koa();
app.use((ctx) => {
    let url = ctx.request.url;
    ctx.body = url;
    console.log(ctx);
});
app.listen(3000);

i want to log 'ctx' in chrome.
but i got this problem:

RangeError: Maximum call stack size exceeded
      at ServerResponse.get (_http_outgoing.js:114:16)
      at ServerResponse.getHeaders (/Users/cyw/Desktop/learnByself/koa2-gitbook-node/node_modules/restify/lib/response.js:177:17)
      at ServerResponse.get (_http_outgoing.js:115:17)
      at ServerResponse.getHeaders (/Users/cyw/Desktop/learnByself/koa2-gitbook-node/node_modules/restify/lib/response.js:177:17)
      at ServerResponse.get (_http_outgoing.js:115:17)
      at ServerResponse.getHeaders (/Users/cyw/Desktop/learnByself/koa2-gitbook-node/node_modules/restify/lib/response.js:177:17)
      at ServerResponse.get (_http_outgoing.js:115:17)
      at ServerResponse.getHeaders (/Users/cyw/Desktop/learnByself/koa2-gitbook-node/node_modules/restify/lib/response.js:177:17)
      at ServerResponse.get (_http_outgoing.js:115:17)
      at ServerResponse.getHeaders (/Users/cyw/Desktop/learnByself/koa2-gitbook-node/node_modules/restify/lib/response.js:177:17)

there is no recursive call in my code, how this happen?

@jwarkentin
Copy link
Owner

That is definitely strange. I will have to try and reproduce it in a few hours (after I get a little sleep). Whatever it is, it shouldn't be too difficult to sort out.

@jwarkentin jwarkentin added the bug label Oct 11, 2017
@jwarkentin
Copy link
Owner

Hey, sorry I wasn't able to get back to you yesterday. The issue here is some sort of bad interaction with Restify. I will have to look into it this weekend. The good news is, Node Monkey has a feature that allows you to provide your own server as documented here. Since I don't have a Koa example there yet, here is some code based on yours that will work:

const NodeMonkey = require('node-monkey')
const Koa = require('koa')
const mount = require('koa-mount')
const send = require('koa-send')

const app = new Koa()
const monk = NodeMonkey({
  server: {
    server: app.listen(3000)
  }
})

const monkPaths = monk.getServerPaths()
app.use(mount('/monkey.js', async ctx => await send(ctx, monkPaths.client, { root: monkPaths.basePath })))
app.use(mount('/monkey', async ctx => await send(ctx, monkPaths.index, { root: monkPaths.basePath })))

app.use(async (ctx, next) => {
  await next()

  let url = ctx.request.url
  ctx.body = url
  console.log(ctx)
})

Note that you'll have to install koa-mount and koa-send for those to work. To access the Node Monkey output you should then open a new tab, open your dev console and go to http://localhost:3000/monkey to see output from your app. Also, keep in mind that even though your code sets ctx.body you will not actually see it in the object dumped to the console because if you look in the Koa source code you'll notice ctx.body only exists as a delegated getter/setter. Just didn't want you to be confused when you don't see it there.

@OleileiA
Copy link
Author

thanks for your advice, i'll try to understand what you told me about ctx.body. Don't worry about the code, relax and have fun at the weekend:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants