From 1249393d91cdf937f146b67fbeee72c8e3454d39 Mon Sep 17 00:00:00 2001 From: Matt Stern Date: Thu, 23 Dec 2021 11:27:54 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20serve=20the=20asserts=20f?= =?UTF-8?q?rom=20nginx=20instead=20of=20starlette?= 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 ++++++++ src/datasets_preview_backend/io/asset.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) 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/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