Skip to content

Commit

Permalink
fix: 馃悰 serve the asserts from nginx instead of starlette (#103)
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
severo committed Dec 23, 2021
1 parent e137280 commit bfa69af
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
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 pyproject.toml
Expand Up @@ -2,7 +2,7 @@
authors = ["Sylvain Lesage <severo@rednegra.net>"]
description = "API to extract rows of 馃 datasets"
name = "datasets-preview-backend"
version = "0.15.7"
version = "0.15.8"

[tool.poetry.dependencies]
Pillow = "^8.4.0"
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 bfa69af

Please sign in to comment.