shaka-project / express-chocolatey-server

Simple Chocolatey package server for Express
5 stars 5 forks source link

Download URLs do not work with a proxy server in front #7

Open bbrendon opened 1 month ago

bbrendon commented 1 month ago

I spun this up and have haproxy forwarding to express. The SSL is on HAproxy, and express is running as http.

I added the haproxy URL using https as source to choco.

I get back :

...
Installing the following packages:
openssl
By installing, you accept licenses for the packages.
Downloading package from source 'https://url.com/'
[NuGet] Error downloading 'chocolatey-windowsupdate.extension.1.0.5' from 'http://url.com/download/chocolatey-windowsupdate.extension'.
[NuGet] An error occurred while sending the request.

Notice above the https is missing from the nuget line?

Any solutions?

I'm going to attempt an HTTP -> HTTPS redirect but that isn't the best solution.

joeyparrish commented 1 month ago

Is chocolatey constructing that plain HTTP URL, or is the server constructing a plain HTTP URL in response to some HTTPS request?

joeyparrish commented 1 month ago

This could be relevant:

https://github.com/shaka-project/express-chocolatey-server/blob/750d8f92a0d31db3f79b595e521a1473da9eed13/chocolatey-server.js#L98-L105

And this:

https://github.com/shaka-project/express-chocolatey-server/blob/750d8f92a0d31db3f79b595e521a1473da9eed13/chocolatey-server.js#L176-L186

I think this explains it. This server will construct absolute URLs based on the request, which is the plain HTTP request forwarded from HAProxy.

This zero-config scheme I built doesn't work with a proxy, since the underlying server can't know the address of the proxy.

I think you would need to add some config to supply the URL root when using a proxy.

I suggest you send a PR that:

  1. Adds a URL root parameter to configureRoutes. If null/undefined, the existing behavior is used where we deduce the URL root from the incoming request in formatPackages.
  2. Add a parameter parser (we use yargs in our other JS projects) and a command-line argument in cli.js to supply this config to configureRoutes.
  3. Add an example of this to the "Standalone server" section of README.md