Search code examples
laravelproxygulp

Laravel(@8000) + Angular with Gulp(@9000), how could I let gulp proxy the 8000 port when requesting 9000?


As I wrote on the subject, I'm using Laravel + Angular(with Gulp) in my project.

But it's always being a problem when I wanna request the APIs provided by Laravel.

Our frontend project is using Gulp, which will start a simple server on 9000 port in development, but the Lavarel owns 8000 port.

It's not only about Cross-Origin, but also about the Auth of account...

So I came out that I could apply a proxy middleware in gulpfile.js of my Angular project. It should proxy the request from 9000 to 8000, and response 9000 with the result of 8000.

But it's totally strange: There was no problem if the proxy target is Facebook, Google... but there has always been a problem if I want to proxy "localhost:8000".

I don't know if Laravel has some kind of mechanisms for rejecting the requests from the proxy?

Or do you have any other ideas that to make things work in my case?


Solution

  • Not a Laravel user. But I think it has been answered in the issue tracker of http-proxy-middleware.

    Try starting the server as such:

    jchayan: php artisan serve --host 0.0.0.0

    awdyer: php artisan serve --host 127.0.0.1