angular-http-server icon indicating copy to clipboard operation
angular-http-server copied to clipboard

Add simple proxy

Open AVierwind opened this issue 2 years ago • 2 comments

Add's a simple proxy to the project. Proxy should be configured by adding a proxyConfig to your config file. For details view README.md #30

AVierwind avatar Aug 05 '22 12:08 AVierwind

This looks rather cool. Let me take some time to review it. But could you first add some extra comments about what the use case is for the option - i just want to make sure we are on the same page

simonh1000 avatar Aug 06 '22 07:08 simonh1000

I have a couple of apps that will do an API request to they own host, in production cases the webserver wil proxy those requests to the web api's. This option wil mimic that behavior to make it possible to run those apps on this server. example: When my app starts it will do a request to /api-proxy/get-user-data which is proxied to the actual api. This simple proxy can be used to proxy those request to a mockserver so i can also use this server to spin up those apps

AVierwind avatar Aug 06 '22 08:08 AVierwind

Hi there. I tried it out and hit a small issue. I want the server to run without having to worry about https, but if I don't use --https then your code uses http when it forwards requests, which will generally fail. I looked at how webpack do it and they provide an option to add protocol: 'http:' in their config. Do you think it would make sense to have it here.

(the problem is exacerbated by the fact that the --https option no longer seems to create assets that chrome will accept - not your problem, but it makes using your option harder. How do you use it?)

simonh1000 avatar Aug 13 '22 12:08 simonh1000

Hi there. I tried it out and hit a small issue. I want the server to run without having to worry about https, but if I don't use --https then your code uses http when it forwards requests, which will generally fail. I looked at how webpack do it and they provide an option to add protocol: 'http:' in their config. Do you think it would make sense to have it here.

(the problem is exacerbated by the fact that the --https option no longer seems to create assets that chrome will accept - not your problem, but it makes using your option harder. How do you use it?)

I Just pushed a change, which adds a protocol option to the config instead of listening to the --htttps option. When absent https will be the default

AVierwind avatar Aug 13 '22 14:08 AVierwind

I tried to test again - see https://github.com/simonh1000/angular-http-server/pull/48 - and still cant get it to work. I've run into a cloudflare issue Direct IP access not allowed. My guess is that your branch is tuned to your use case, but I've learnt in my ftp packager that in the wide world of network communications all sorts of weirdness can happen.

I'm going to try to build a server on my machine and proxy to that.

one change that I tried that got me past the first error but not the second was

httpProxy.createProxyServer({
      secure: false,
});

Any views on this?

simonh1000 avatar Aug 19 '22 07:08 simonh1000

I have now got it to work on my machine with a reasonable test case. There is the bug above but then we can merge

simonh1000 avatar Aug 20 '22 09:08 simonh1000

Cool, will merge and release a new version at the weekend

simonh1000 avatar Aug 24 '22 05:08 simonh1000