Skip to content

Commit

Permalink
fix: 🐛 serve the asserts from nginx instead of starlette
Browse files Browse the repository at this point in the history
Starlette cannot serve ranges for static files, see
encode/starlette#950.

Also: fix the rights of the assets directory
Also: add the CORS header (doc)
  • Loading branch information
mattstern31 committed Dec 23, 2021
1 parent f83ff81 commit 1249393
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions INSTALL.md
Expand Up @@ -112,9 +112,17 @@ server {
listen [::]:80;
server_name datasets-preview.huggingface.tech;

add_header 'Access-Control-Allow-Origin' '*';

access_log /var/log/nginx/reverse-access.log;
error_log /var/log/nginx/reverse-error.log;

# due to https://github.com/encode/starlette/issues/950, which generates errors in Safari: https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariWebContent/CreatingVideoforSafarioniPhone/CreatingVideoforSafarioniPhone.html#//apple_ref/doc/uid/TP40006514-SW6
# we serve the static files from nginx instead of starlette
location /assets {
root /home/hf/.cache/datasets_preview_backend_assets
}

location / {
proxy_pass http://localhost:8000/;
proxy_set_header Host $proxy_host;
Expand Down
2 changes: 1 addition & 1 deletion src/datasets_preview_backend/io/asset.py
Expand Up @@ -13,7 +13,7 @@
logger = logging.getLogger(__name__)

DATASET_SEPARATOR = "--"
ASSET_DIR_MODE = 755
ASSET_DIR_MODE = 0o755

# set it to the default cache location on the machine, if ASSETS_DIRECTORY is null
assets_directory = user_cache_dir("datasets_preview_backend_assets") if ASSETS_DIRECTORY is None else ASSETS_DIRECTORY
Expand Down

0 comments on commit 1249393

Please sign in to comment.