fix(middleware): instantiate locals if the adapter does not
This commit is contained in:
parent
a8b979ef40
commit
89fbeb34b8
1 changed files with 12 additions and 1 deletions
|
@ -76,7 +76,18 @@ export function createAPIContext({
|
|||
Object.defineProperty(context, 'locals', {
|
||||
enumerable: true,
|
||||
get() {
|
||||
return Reflect.get(request, clientLocalsSymbol);
|
||||
let locals = Reflect.get(request, clientLocalsSymbol)
|
||||
|
||||
if (locals === undefined) {
|
||||
locals = {}
|
||||
Reflect.set(request, clientLocalsSymbol, locals)
|
||||
}
|
||||
|
||||
if (typeof locals !== 'object') {
|
||||
throw new AstroError(AstroErrorData.LocalsNotAnObject);
|
||||
}
|
||||
|
||||
return locals;
|
||||
},
|
||||
set(val) {
|
||||
if (typeof val !== 'object') {
|
||||
|
|
Loading…
Reference in a new issue