doccano icon indicating copy to clipboard operation
doccano copied to clipboard

Add option to serve with URL prefix

Open Vinno97 opened this issue 2 years ago • 4 comments

Added the option to run Doccano with a URL prefix instead of always running from the domain root. The prefix is configured by specifying a BASE_URL environment variable. This PR fixes #1878

To run Doccano under /doccano/, set BASE_URL to /doccano/:

export BASE_URL=/doccano/

When we now compile the front-end, all routes are prefixed with BASE_URL.

We also need to let Django know about our new prefix. This is done using the same BASE_URL environment variable but needs to be set during runtime. I could not find a clean method to configure them both during runtime.

Since such a configuration will most likely only be used in combination with a load balancer, I also added the option to set USE_X_FORWARDED_HOST using environment variables.

Note that I did not write any tests for this (yet), both because I am unsure how this should be done and because I would first like to know if this PR would be acceptable.

Vinno97 avatar Sep 19 '22 16:09 Vinno97

Thanks!

Please write some test cases. After that, I'll merge this PR.

Hironsan avatar Sep 20 '22 02:09 Hironsan

Great, will do. Any tips about where to start for someone unfamiliar with the project (and Django in general)? I expect I should extend backend/api/tests/test_config.py?

Vinno97 avatar Sep 20 '22 10:09 Vinno97

Still in progress? @Vinno97

lyingcrow avatar Apr 18 '23 03:04 lyingcrow

This hasn't been on my radar for quite a long time. The project I needed this fix for, was finished up a while ago. I'd be willing to write some tests for it, but I'm still equally unfamiliar with the project and Django. So some pointers will be needed

Vinno97 avatar Jul 03 '23 06:07 Vinno97