CORS
Allow fetch from other origins with cors()
import { , } from "@senrijs/senri";
const = ();
.("/api", ({ : ["https://example.com"], : true }));- It answers preflight requests (OPTIONS with
Access-Control-Request-Method) with 204 itself - It adds CORS headers to other responses. For origins that are not allowed, it adds nothing
- Unless
originis"*", it addsVary: Origin origindefaults to"*"(any origin).credentials: truecannot be used withorigin: "*"(it throws)- With authentication such as
basicAuth(), registercors()first, because preflight requests carry no credentials
Decide the origin with a function
.(({ : () => .(".example.com") }));Returning true allows that origin, and returning a string sends that value. false, null or undefined denies it.
Options
Prop
Type