Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed: Fix reversed section URL prefix #1024

Merged
merged 4 commits into from
May 22, 2024
Merged

Conversation

drikusroor
Copy link
Contributor

@drikusroor drikusroor commented May 21, 2024

This PR prefixes the section urls from the absolute_url method in the section's model.py with an optional BASE_URL while removing the earlier used MEDIA_ROOT prefix from the fetch section actions in the frontend. This will make sure that the backend returns the correct section url while the frontend won't add a redundant /server path prefix.

There are two scenarios, which both require a slightly different configuration:

  1. Local develop environment
  2. Test / Acceptance / Production environments

1. Local develop environment

As the frontend runs on localhost:3000 and the backend on localhost:8000, the returned section url needs to be prefixed with http://localhost:8000 in the backend, as the MEDIA_ROOT (aka the API_ROOT) doesn't do that anymore in the frontend. In Django's develop settings, the BASE_URL setting is set to http://localhost:8000 by default. The absolute_url method therefore returns "http://localhost:8000" + "/section/123/456" = http://localhost:8000/section/123/456.

2. Test / Acceptance / Production environments

As the frontend and the backend run on the same (sub) domain, BASE_URL needn't be configured. It therefore defaults to an empty string. The absolute_url method will therefore return "" + "/section/123/456" = "/section/123/456". The frontend does not prefix this url with anything but fetches the path from the domain it is running on: https://(tst/acc/prd).amsterdammusiclab.nl/section/123/456.

How to test

Local develop environment

You do not need to set BASE_URL to http://localhost:8000 in your .env file as it will already default to that value in Django's develop settings. Simply check if the audio and other files in the experiments are still working.

Other environments

I've deployed this branch to the test environment using the workflow dispatch method (see here) and verified that the audio playback works for this matching pairs experiment: https://tst.amsterdammusiclab.nl/introductiono

Resolves #1020

@drikusroor drikusroor self-assigned this May 21, 2024
@drikusroor drikusroor force-pushed the fix/1020-fix-fetch-sections branch from 405a10e to 0af4025 Compare May 21, 2024 20:43
@drikusroor drikusroor marked this pull request as ready for review May 21, 2024 20:56
@drikusroor
Copy link
Contributor Author

Alternatively, I could also simplify it and hard-code the localhost:8000 in the absolute_url method whenever we are in develop mode..

Copy link
Collaborator

@BeritJanssen BeritJanssen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

…ASE_URL as an empty string

(cherry picked from commit 0af4025)
Co-authored-by: Berit <berit.janssen@gmail.com>
(cherry picked from commit 3ef3397)
@drikusroor drikusroor force-pushed the fix/1020-fix-fetch-sections branch from 3ef3397 to f09d025 Compare May 22, 2024 08:59
@drikusroor drikusroor changed the base branch from develop to main May 22, 2024 08:59
@drikusroor drikusroor merged commit 681daa3 into main May 22, 2024
8 checks passed
@drikusroor drikusroor deleted the fix/1020-fix-fetch-sections branch May 22, 2024 09:05
@drikusroor drikusroor restored the fix/1020-fix-fetch-sections branch May 27, 2024 08:26
drikusroor added a commit that referenced this pull request May 27, 2024
…ll (#1034)

* Fixed: Fix reversed section URL prefix (#1024)

* fix: Prefix reversed section url with BASE_URL if present

(cherry picked from commit b42f649)

* chore: Add BASE_URL environment variable to production settings too

(cherry picked from commit 0b4f6d8)

* refactor: Fallback to "http://localhost:8000" even when Docker sets BASE_URL as an empty string

(cherry picked from commit 0af4025)

* refactor: Strip trailing slash from base url

Co-authored-by: Berit <berit.janssen@gmail.com>
(cherry picked from commit 3ef3397)

* chore: Update package version to 2.1.0

* chore: Add release workflow for created releases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐛 [BUG] - Preload and audio.js still include MEDIA_ROOT
2 participants