WordPress / openverse-api

The Openverse API allows programmatic access to search for CC-licensed and public domain digital media.
https://api.openverse.engineering/v1
MIT License
77 stars 51 forks source link

Add PATH_PREFIX configuration #1136

Open sarayourfriend opened 1 year ago

sarayourfriend commented 1 year ago

Fixes

Related to an effort to deploy the Django application to an /api path on a shared domain.

Description

This work is still WIP and the PR exists mostly to demonstrate the current difficulties. All of the troublesome parts (the circular imports) can be avoided if we switch to Caddy instead of Nginx and just re-write the path before forwarding it to the Django service. See the commit descriptions for more details on the issues.

Testing Instructions

Add a PATH_PREFIX variable to your api/.env file. I used PATH_PREFIX=totally_bogus_dude. Then navigate to http://localhost:50280/ and confirm that nothing appears unless you to go http://localhost:50280/totally_bogus_dude/ or whatever you set the PATH_PREFIX to.

Note that right now the app won't start due to a circular import that I'm not sure how to resolve (and which can be avoided if we use Caddy instead, because we could bypass fixing the not-technically-safe ignoring of reverse in building URLs).

Checklist

[best_practices]: https://git-scm.com/book/en/v2/Distributed-Git-Contributing-to-a-Project#_commit_guidelines

Developer Certificate of Origin

Developer Certificate of Origin ``` Developer Certificate of Origin Version 1.1 Copyright (C) 2004, 2006 The Linux Foundation and its contributors. 1 Letterman Drive Suite D4700 San Francisco, CA, 94129 Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Developer's Certificate of Origin 1.1 By making a contribution to this project, I certify that: (a) The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or (b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or (c) The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it. (d) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved. ```