-
-
Notifications
You must be signed in to change notification settings - Fork 173
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
no res.redirect? #78
Comments
Think I figured it out ` res.writeHead(301, { Location: encodeUrl(myurl) }); Thanks for the help, think I would have never find it out alone |
TIL. Thanks man.
…On Wed, Dec 19, 2018, 1:59 PM Olivier Refalo ***@***.***> wrote:
Think I figured it out
`
import * as encodeUrl from 'encodeurl';
...
res.writeHead(301, { Location: encodeUrl(myurl) });
res.end();
`
Thanks for the help, think I would have never find it out alone
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#78 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AKHcj-dZqYqeqK2G2h3tSWU557eKgDRwks5u6dW7gaJpZM4ZY_6A>
.
|
Oh, sorry guys. Didn't know there was a question for how to do a redirect. Thought this was just a tracker for let url = 'https://.../foo/bar';
let str = `Redirecting to ${url}`;
res.writeHead(302, {
Location: url,
'Content-Type': 'text/plain',
'Content-Length': str.length
});
res.end(str); This is pulled from one of my projects. It displays text in the browser for a moment – which isn't necessary but I chose to have it here. |
for compatibility with with other express middlewares like passport, a res.redirect function might also be a good idea |
should anyone stumble upon this, I solved my issue by added the method to the res object in a middleware like this: polka()
.use(function(req, res, next) {
res.redirect = location => {
let str = `Redirecting to ${location}`;
res.writeHead(302, {
Location: location,
'Content-Type': 'text/plain',
'Content-Length': str.length,
});
res.end(str);
};
next();
}) |
No description provided.
The text was updated successfully, but these errors were encountered: