|
| 1 | +map $http_accept $wants_markdown { |
| 2 | + default 0; |
| 3 | + "~*text/markdown" 1; |
| 4 | + "~*text/plain" 1; |
| 5 | +} |
| 6 | + |
1 | 7 | server { |
2 | 8 | listen 0.0.0.0:8080; |
3 | 9 | server_name 'docs.apify.com'; |
4 | 10 |
|
| 11 | + # homepage: only rewrite to internal proxy when client wants markdown |
| 12 | + location = / { |
| 13 | + if ($wants_markdown) { |
| 14 | + # use 'last' to force a new location lookup so /__proxy/ handler runs |
| 15 | + rewrite ^ /__proxy/llms.txt last; |
| 16 | + } |
| 17 | + proxy_pass http://localhost:3000; |
| 18 | + } |
| 19 | + |
| 20 | + # direct llms.txt files, serve with markdown content type |
| 21 | + location ~ ^/llms(-full)?\.txt$ { |
| 22 | + proxy_pass http://localhost:3000; |
| 23 | + proxy_hide_header Content-Type; |
| 24 | + add_header Content-Type "text/markdown; charset=utf-8" always; |
| 25 | + } |
| 26 | + |
| 27 | + # generic docs fallback: rewrite clean URLs to .md when client wants markdown |
5 | 28 | location / { |
6 | | - proxy_pass https://apify.github.io/apify-docs/; |
| 29 | + if ($wants_markdown) { |
| 30 | + # rewrite to internal proxy path; use last so new location is matched |
| 31 | + rewrite ^(/[^.]+)$ /__proxy$1.md last; |
| 32 | + } |
| 33 | + proxy_pass http://localhost:3000; |
| 34 | + } |
| 35 | + |
| 36 | + # internal proxy handler that actually forces the markdown header |
| 37 | + location ^~ /__proxy/ { |
| 38 | + internal; |
| 39 | + |
| 40 | + # strip the /__proxy prefix so upstream sees the real path |
| 41 | + rewrite ^/__proxy(/.*)$ $1 break; |
| 42 | + |
| 43 | + proxy_pass http://localhost:3000; |
| 44 | + proxy_hide_header Content-Type; |
| 45 | + add_header Content-Type "text/markdown; charset=utf-8" always; |
7 | 46 | } |
| 47 | + |
| 48 | + # proxies to other repositories |
8 | 49 | location /api/client/js { |
9 | 50 | proxy_pass https://apify.github.io/apify-client-js/; |
10 | 51 | } |
|
0 commit comments