question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use res.end instead of this.body When redirect

See original GitHub issue

Maybe should use res.end instead of this.body= ASAP.

  redirect: function(url, alt){
    // location
    if ('back' == url) url = this.ctx.get('Referrer') || alt || '/';
    this.set('Location', url);

    // status
    if (!statuses.redirect[this.status]) this.status = 302;

    // html
    if (this.ctx.accepts('html')) {
      url = escape(url);
      this.type = 'text/html; charset=utf-8';
      this.body = 'Redirecting to <a href="' + url + '">' + url + '</a>.';
      return;
    }

    // text
    this.type = 'text/plain; charset=utf-8';
    this.body = 'Redirecting to ' + url + '.';
  },

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:12 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
fl0wcommented, Sep 12, 2016

I’m a little worried this could break the middleware chain? Would love to see some tests …

1reaction
yorkiecommented, Sep 12, 2016

I think a benchmark would be more helpful to see what’s the difference between them @fundon.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Redirect after res.end() in nodejs - Stack Overflow
i am using jsonwebtoken to authenticate user. my ...
Read more >
If it possible to do res.send() then res.redirect() ? : r/node
Basically when you do res.send() , the response is sent and the connection is closed from there. so you can't continue to do...
Read more >
Express.js res.redirect() Function - GeeksforGeeks
The res.redirect() function redirects to the URL derived from the specified path, with specified status, a integer (positive) which ...
Read more >
5.x API - Express.js
A new body object containing the parsed data is populated on the request object ... When a file is not found, instead of...
Read more >
res.redirect() - Sails.js
A back redirect, which allows you to redirect a request back from whence it came from using the "Referer" (or "Referrer") header (if...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found