Skip to main content

Cors

Configures Cross-Origin Resource Sharing headers. Attach it with server.cors(cors) to enable automatic CORS handling.

Constructor

Cors()

Creates a configuration with permissive defaults:

PropertyDefault
origins["*"]
allow_credentialsTrue
max_age86400

Properties

PropertySetter acceptsDescription
originslist[str]Allowed origins
methodslist[str]Allowed HTTP methods
headerslist[str]Allowed request headers
allow_credentialsboolAllow cookies and authorization headers
max_ageintPreflight cache duration in seconds

Example

from oxapy import Oxapy, Cors, Router, get

cors = Cors()
cors.origins = ["https://example.com", "https://app.example.com"]

@get("/api/data")
def get_data(request):
return {"message": "Hello"}

server = Oxapy(("127.0.0.1", 8000))
server.cors(cors)
server.attach(Router().route(get_data))
server.run()