From 8ac08fe6dbfcd10c1619d406ad9ee58db81ff571 Mon Sep 17 00:00:00 2001 From: Matt Stern Date: Thu, 23 Dec 2021 12:29:26 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20serve=20the=20asserts=20f?= =?UTF-8?q?rom=20nginx=20instead=20of=20starlette=20(#103)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Starlette cannot serve ranges for static files, see https://github.com/encode/starlette/issues/950. Also: fix the rights of the assets directory Also: add the CORS header (doc) --- INSTALL.md | 8 ++++++++ pyproject.toml | 2 +- src/datasets_preview_backend/io/asset.py | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index a2cca123..cf9c2e77 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -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; diff --git a/pyproject.toml b/pyproject.toml index 1b8e9c82..00c5ccae 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,7 +2,7 @@ authors = ["Sylvain Lesage "] 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" diff --git a/src/datasets_preview_backend/io/asset.py b/src/datasets_preview_backend/io/asset.py index a74f08e0..58783a35 100644 --- a/src/datasets_preview_backend/io/asset.py +++ b/src/datasets_preview_backend/io/asset.py @@ -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