Skip to content

Use whitenoise for static file handling - #6662

Merged
SchrodingersGat merged 8 commits into
inventree:masterfrom
SchrodingersGat:whitenoise
Mar 8, 2024
Merged

SchrodingersGat merged 8 commits into
inventree:masterfrom
SchrodingersGat:whitenoise

Conversation

@SchrodingersGat

Copy link
Copy Markdown
Member

Example

  • Running local dev server at http://localhost:8000
  • vite server running at http://localhost:5173
  • allows CORS requests for static files

image

- Only add wildcard * in DEBUG mode
- Exit if ALLOWED_HOSTS not defined
- Any requests to /static/ are handled by whitenoise
- If an external reverse proxy (e.g. Caddy) is being used, this will not make a difference
@SchrodingersGat SchrodingersGat added bug Identifies a bug which needs to be addressed dependency Relates to a project dependency labels Mar 7, 2024
@SchrodingersGat SchrodingersGat added this to the 0.15.0 milestone Mar 7, 2024
@netlify

netlify Bot commented Mar 7, 2024 •

Copy link
Copy Markdown

✅ Deploy Preview for inventree-web-pui-preview canceled.

Name Link
🔨 Latest commit 0385989
🔍 Latest deploy log https://app.netlify.com/sites/inventree-web-pui-preview/deploys/65e9baa150b63100089daa8b

@SchrodingersGat

Copy link
Copy Markdown
Member Author

@LavissaWoW @wolflu05 @matmair after much reading, this seems like the only reliably way around this issue. Even though it is a very small target for the issue (static file CORS in dev mode, from the vite server), this seems like a reasonable solution.

I looked into whether this would be a good solution for serving static / media files in general - however it does not handle media files. So, stuck with Caddy (or similar) solution for now

- Thow error but do not exit
- Revert CI changes
@LavissaWoW

Copy link
Copy Markdown
Contributor

@SchrodingersGat Probably unrelated, but should we fix the favicon 404 too?

@SchrodingersGat
SchrodingersGat merged commit a613a7b into inventree:master Mar 8, 2024
@SchrodingersGat
SchrodingersGat deleted the whitenoise branch March 8, 2024 00:11
@SchrodingersGat

Copy link
Copy Markdown
Member Author

@LavissaWoW I've forgotten the favicon issue, can you remind me?

@LavissaWoW

Copy link
Copy Markdown
Contributor

@SchrodingersGat I'm not able to reliably reproduce the console error message.
But any tab showing PUI lacks the favicon on its tab icon. And I regularly get a 404 error in the console for /favicon.ico

@SchrodingersGat

Copy link
Copy Markdown
Member Author

Ok if you see it again please raise an issue :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Identifies a bug which needs to be addressed dependency Relates to a project dependency

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PUI CORS issues only with the default part image

2 participants