Worker CORS¶
gutenberg_kg.serve.cors
¶
CORS for the local worker, so the Knowledge Press Forest can call it.
RunPod's local API server (--rp_serve_api) sends no CORS headers, so a
browser page cannot read its answers. :class:CORSMiddleware is plain ASGI:
it answers preflight requests from the allowed origins and adds
Access-Control-Allow-Origin to their responses. A request from any other
origin passes through untouched, without CORS headers, so the browser refuses
it as before.
The handler installs it only when GUTENKG_CORS_ORIGINS is set (see
:func:cors_origins).
CORSMiddleware(app, origins)
¶
Allow POST requests from a fixed set of origins.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app
|
The ASGI app to wrap. |
required | |
origins
|
frozenset[str]
|
The allowed origins, as :func: |
required |
Source code in src/gutenberg_kg/serve/cors.py
47 48 49 | |
cors_origins(value)
¶
The allowed origins in a GUTENKG_CORS_ORIGINS value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
Comma-separated origins, e.g.
|
required |
Returns:
| Type | Description |
|---|---|
frozenset[str]
|
Each origin, trimmed, without a trailing slash; empty for |
Source code in src/gutenberg_kg/serve/cors.py
23 24 25 26 27 28 29 30 | |