docker-examples icon indicating copy to clipboard operation
docker-examples copied to clipboard

nginx relative path example depends on assets served from root

Open bsh-ableton opened this issue 4 years ago • 1 comments

Hello,

I just bumped into a little snag trying to use Verdaccio in an environment where it is reverse-proxied with a url_prefix. I thought I'd document what I found; hopefully this is helpful!

summary

In the nginx reverse proxy example with a relative path, the Verdaccio instance at /verdaccio/ points to the static assets served by the instance at /.

Because both of these instances are the same version, it conceals an underlying issue: that setting a url_prefix in Verdaccio v4's config.yaml doesn't lead to the url_prefix being used for the accompanying static assets.

reproduction

git clone https://github.com/verdaccio/docker-examples.git verdaccio-docker-examples
cd verdaccio-docker-examples/reverse_proxy/nginx/relative_path/
docker-compose build
docker-compose up

This starts Verdaccio instances at / (v4), /verdaccio/ (v4), and /verdacciov3/ (v3). They all look and operate fine.

However, the source code in the /verdaccio/ instance refers to assets using URLs beginning with /, rather than /verdaccio/ as specified in the url_prefix:

<script type="text/javascript" src="/-/static/manifest.ba207bfcf72b6ad80f79.js"></script><script type="text/javascript" src="/-/static/vendors.ba207bfcf72b6ad80f79.js"></script><script type="text/javascript" src="/-/static/main.ba207bfcf72b6ad80f79.js"></script></body>

When I access /verdaccio/, I see log entries from both the verdaccio_relative_path_v4 and verdaccio_relative_path_v4_root containers.

If I then disable the verdaccio_relative_path_v4_root container and refresh the browser, the /verdaccio/ page turns white, and the browser developer tools show these resources failed to load. The instance at /verdacciov3/ continues functioning unaffected.

why's this an issue?

In my use case, I need to confine Verdaccio completely to a subdirectory using url_prefix, so serving the static assets from the the root of the domain is unfortunately not feasible.

related issues

See: #10 See: verdaccio/verdaccio#1299, verdaccio/verdaccio#1297

Many thanks, Braxton

bsh-ableton avatar Nov 04 '19 18:11 bsh-ableton

This is confirmed in more detail by verdaccio/verdaccio#1523, and it appears to be introduced by https://github.com/verdaccio/ui/pull/122.

I can confirm that the resources load properly when I revert that change, or add ToReplaceByVerdaccio/ manually to the three imports in verdaccio-ui's static/index.html. Unfortunately, simply reverting isn't possible because that would reintroduce https://github.com/verdaccio/ui/issues/108.

bsh-ableton avatar Aug 29 '20 16:08 bsh-ableton