Refactor documentation for reverse proxy and routing guides
Deploy to Production / deploy (push) Successful in 5s
Deploy to Production / deploy (push) Successful in 5s
This commit is contained in:
+38
-38
@@ -62,29 +62,29 @@
|
||||
<h3>Routing Configuration</h3>
|
||||
<p>Routing is configured via the <code>routing</code> extension:</p>
|
||||
|
||||
<pre><span class="directive">extensions:</span>
|
||||
- <span class="directive">type:</span> <span class="value">routing</span>
|
||||
<span class="directive">config:</span>
|
||||
<span class="directive">regex_locations:</span>
|
||||
<span class="comment"># Exact match for health check</span>
|
||||
<span class="value">"=/health"</span>:
|
||||
<span class="directive">return:</span> <span class="value">"200 OK"</span>
|
||||
<span class="directive">content_type:</span> <span class="value">"text/plain"</span>
|
||||
<pre><code class="language-yaml">extensions:
|
||||
- type: routing
|
||||
config:
|
||||
regex_locations:
|
||||
# Exact match for health check
|
||||
"=/health":
|
||||
return: "200 OK"
|
||||
content_type: "text/plain"
|
||||
|
||||
<span class="comment"># Static files with caching</span>
|
||||
<span class="value">"~*\\.(js|css|png|jpg|gif|ico)$"</span>:
|
||||
<span class="directive">root:</span> <span class="value">"./static"</span>
|
||||
<span class="directive">cache_control:</span> <span class="value">"public, max-age=31536000"</span>
|
||||
# Static files with caching
|
||||
"~*\\.(js|css|png|jpg|gif|ico)$":
|
||||
root: "./static"
|
||||
cache_control: "public, max-age=31536000"
|
||||
|
||||
<span class="comment"># HTML files without caching</span>
|
||||
<span class="value">"~*\\.html$"</span>:
|
||||
<span class="directive">root:</span> <span class="value">"./static"</span>
|
||||
<span class="directive">cache_control:</span> <span class="value">"no-cache"</span>
|
||||
# HTML files without caching
|
||||
"~*\\.html$":
|
||||
root: "./static"
|
||||
cache_control: "no-cache"
|
||||
|
||||
<span class="comment"># Default fallback</span>
|
||||
<span class="value">"__default__"</span>:
|
||||
<span class="directive">root:</span> <span class="value">"./static"</span>
|
||||
<span class="directive">index_file:</span> <span class="value">"index.html"</span></pre>
|
||||
# Default fallback
|
||||
"__default__":
|
||||
root: "./static"
|
||||
index_file: "index.html"</code></pre>
|
||||
|
||||
<h3>Location Directives</h3>
|
||||
|
||||
@@ -120,11 +120,11 @@
|
||||
<h3>Named Capture Groups</h3>
|
||||
<p>Regex locations support named capture groups that can be used in headers and proxy URLs:</p>
|
||||
|
||||
<pre><span class="value">"~^/api/v(?P<version>\\d+)/(?P<resource>\\w+)"</span>:
|
||||
<span class="directive">proxy_pass:</span> <span class="value">"http://backend:9001"</span>
|
||||
<span class="directive">headers:</span>
|
||||
- <span class="value">"X-API-Version: {version}"</span>
|
||||
- <span class="value">"X-Resource: {resource}"</span></pre>
|
||||
<pre><code class="language-bash">"~^/api/v(?P<version>\\d+)/(?P<resource>\\w+)":
|
||||
proxy_pass: "http://backend:9001"
|
||||
headers:
|
||||
- "X-API-Version: {version}"
|
||||
- "X-Resource: {resource}"</code></pre>
|
||||
|
||||
<p>Request to <code>/api/v2/users</code> will have headers:</p>
|
||||
<ul class="indent">
|
||||
@@ -135,14 +135,14 @@
|
||||
<h3>SPA Configuration</h3>
|
||||
<p>For Single Page Applications, use <code>spa_fallback</code> with <code>exclude_patterns</code>:</p>
|
||||
|
||||
<pre><span class="value">"__default__"</span>:
|
||||
<span class="directive">spa_fallback:</span> <span class="value">true</span>
|
||||
<span class="directive">root:</span> <span class="value">"./dist"</span>
|
||||
<span class="directive">index_file:</span> <span class="value">"index.html"</span>
|
||||
<span class="directive">exclude_patterns:</span>
|
||||
- <span class="value">"/api/"</span>
|
||||
- <span class="value">"/assets/"</span>
|
||||
- <span class="value">"/static/"</span></pre>
|
||||
<pre><code class="language-python">"__default__":
|
||||
spa_fallback: true
|
||||
root: "./dist"
|
||||
index_file: "index.html"
|
||||
exclude_patterns:
|
||||
- "/api/"
|
||||
- "/assets/"
|
||||
- "/static/"</code></pre>
|
||||
|
||||
<p>This will:</p>
|
||||
<ul class="indent">
|
||||
@@ -153,11 +153,11 @@
|
||||
<h3>Static File Serving</h3>
|
||||
<p>Basic static file configuration:</p>
|
||||
|
||||
<pre><span class="value">"~*\\.(css|js|png|jpg|gif|svg|woff2?)$"</span>:
|
||||
<span class="directive">root:</span> <span class="value">"./static"</span>
|
||||
<span class="directive">cache_control:</span> <span class="value">"public, max-age=86400"</span>
|
||||
<span class="directive">headers:</span>
|
||||
- <span class="value">"X-Content-Type-Options: nosniff"</span></pre>
|
||||
<pre><code class="language-bash">"~*\\.(css|js|png|jpg|gif|svg|woff2?)$":
|
||||
root: "./static"
|
||||
cache_control: "public, max-age=86400"
|
||||
headers:
|
||||
- "X-Content-Type-Options: nosniff"</code></pre>
|
||||
|
||||
<div class="note">
|
||||
<strong>Note:</strong> pyserve automatically detects MIME types based on file extensions.
|
||||
|
||||
Reference in New Issue
Block a user