1

I am Using this code.

import { RestApplication } from '@loopback/rest';
    const app = new RestApplication();
          app.redirect('', 'https://www.google.com/');

When i call API it's showing 204 response code but not redirecting to this URL. I'm using loopback4

imran ali
  • 383
  • 1
  • 13

1 Answers1

4

Same way you do with express. Just do it in controller.

  @get('redirect')
  async redirect(@inject(RestBindings.Http.RESPONSE) response: Response) {
    response.redirect('https://www.google.com');
  }

See similar solution with express here

PS:

you must import Response from loopback/rest to work this solution

import {Response} from '@loopback/rest'

Edit after comment

Also you can do it with sequences. Check it here on documentation example.

All above methods are tested on loopback4

Salitha
  • 1,022
  • 1
  • 12
  • 32
  • Hi @Salitha , thanks for answer. it's not working when i have used import {Response} from '@loopback/rest', i have got error ReferenceError: Response is not defined. Response.redirect('https://www.google.com') this is my code – imran ali Mar 11 '20 at 07:37
  • Hey, I updated my answer with two examples. Try them. – Salitha Mar 11 '20 at 14:03
  • Also, check this [git issue](https://github.com/strongloop/loopback-next/issues/1881) . It may help. BTW, what is your loopback 4 version? – Salitha Mar 11 '20 at 14:12