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

Location header #171

Open
anythingagency opened this issue Mar 13, 2019 · 2 comments
Open

Location header #171

anythingagency opened this issue Mar 13, 2019 · 2 comments

Comments

@anythingagency
Copy link

There is currently no way to pass in a Location: header in the beforeRender. This therefore breaks a cached 301 response, as the status is set to 301, but the Location isn't set.

Need to be able to:

done(err, {body: fields[0], status: fields[1], location: fields[2]});

@thoop
Copy link
Contributor

thoop commented Mar 28, 2019

The beforeRender function starts as follows:

prerender.beforeRenderFn(req, function(err, cachedRender) {

    if (!err && cachedRender) {
      if (typeof cachedRender == 'string') {
        res.writeHead(200, {
          "Content-Type": "text/html"
        });
        return res.end(cachedRender);
      } else if (typeof cachedRender == 'object') {
        res.writeHead(cachedRender.status || 200, {
          "Content-Type": "text/html"
        });
        return res.end(cachedRender.body || '');
      }
    }
...

I think we could probably break this out:

res.writeHead(cachedRender.status || 200, {
    "Content-Type": "text/html"
});

into something like:

var status = cachedRender.status || 200;
var headers = cachedRender.headers || { "Content-Type": "text/html" };
res.writeHead(status, headers);

That would let you override the headers being sent back if you are caching those too. What do you think?

@anythingagency
Copy link
Author

Thats would be a perfect solution. Thank you for replying.

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

No branches or pull requests

2 participants