0

In Express, Im able to redirect to other url using response.redirect(""). Similarly how can I redirect in Connect module? I've tried the below code but its not working.

response.setHeader('Content-Type', 'text/plain');
response.end('<p>302. Redirecting to <a href="' + url+ '">' + url+ '</a></p>');
user3180402
  • 579
  • 2
  • 7
  • 16
  • setting the `Location` header is one option. haven't explored the connect api thought, i should be similar to express – Gntem Mar 03 '14 at 09:12

2 Answers2

6

You can also redirect in Connect using writeHead as follows:

res.writeHead(301, {Location: url});
res.end();

The 301 http status code means "moved permanently".

Svbaker
  • 706
  • 3
  • 4
0

res.redirect is defined in express, not in connect (see the relevant source code). You then can't use this function, but you can copy its behavior by setting the Location header:

res.set('Location', url);

You can also read this answer: even if is related to , it contains useful information regarding the use of the header.

Community
  • 1
  • 1
Paul Mougel
  • 16,728
  • 6
  • 57
  • 64