mergeHandlerOptions
Merges the handler options of the file (baked) with the entry's (user).
Merges the handler options of the file (baked) with the entry's (user). The result is a new object; neither input
is changed.
The rules, in short (the entry is user):
- a plain object on both sides is merged key by key, recursively:
security.cspfrom the entry keeps the file'ssecurity.headers; - any other value replaces the file's: a primitive,
false,null, an array, a function, a class instance (its reference is kept). An array is never concatenated:allowedHostsin the entry replaces the file's list; undefinedmeans "not set": it does NOT erase a file value. A key that neither side sets is absent from the result;- the keys
__proto__,constructorandprototypeare ignored at every depth; - a merge may create at most 10 000 objects; more throws a RangeError (a cycle in the input).
Import#
ts
import { mergeHandlerOptions } from "@shadow-js/dusk/server";
Signature#
ts
function mergeHandlerOptions(
baked: Partial<HandlerOptions>,
user: Partial<HandlerOptions> | undefined,
): Partial<HandlerOptions>
Parameters#
| Name | Description |
|---|---|
baked |
The file's options, as serverOptionsFromConfig returns them. |
user |
The entry's options (undefined: none). |
Returns#
The merged options.
Throws#
- RangeError when the inputs are cyclic or nest beyond the object bound.
Examples#
ts
const options = mergeHandlerOptions(
{ security: { allowedHosts: ["example.com"], headers: { frameOptions: "DENY" } } },
{ security: { csp: { directives: { "default-src": ["'self'"] } } } },
);
// security: { allowedHosts: ["example.com"], headers: { frameOptions: "DENY" }, csp: { ... } }