[ci] format
This commit is contained in:
parent
7e9d82d75e
commit
c3b083f286
3 changed files with 13 additions and 10 deletions
|
@ -20,7 +20,7 @@ export function createRequest({
|
|||
method = 'GET',
|
||||
body = undefined,
|
||||
logging,
|
||||
ssr
|
||||
ssr,
|
||||
}: CreateRequestOptions): Request {
|
||||
let headersObj =
|
||||
headers instanceof Headers
|
||||
|
@ -52,20 +52,21 @@ export function createRequest({
|
|||
},
|
||||
});
|
||||
|
||||
if(!ssr) {
|
||||
if (!ssr) {
|
||||
// Warn when accessing headers in SSG mode
|
||||
const _headers = request.headers;
|
||||
const headersDesc = Object.getOwnPropertyDescriptor(request, 'headers') || {};
|
||||
Object.defineProperty(request, 'headers', {
|
||||
...headersDesc,
|
||||
get() {
|
||||
warn(logging,
|
||||
warn(
|
||||
logging,
|
||||
'ssg',
|
||||
`Headers are not exposed in static-site generation (SSG) mode. To enable reading headers you need to set an SSR adapter in your config.`
|
||||
);
|
||||
return _headers;
|
||||
}
|
||||
})
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return request;
|
||||
|
|
|
@ -176,7 +176,7 @@ async function handleRequest(
|
|||
method: req.method,
|
||||
body,
|
||||
logging,
|
||||
ssr: buildingToSSR
|
||||
ssr: buildingToSSR,
|
||||
});
|
||||
|
||||
try {
|
||||
|
|
|
@ -22,12 +22,11 @@ describe('Static build', () => {
|
|||
dest: {
|
||||
write(chunk) {
|
||||
logs.push(chunk);
|
||||
}
|
||||
},
|
||||
},
|
||||
level: 'warn',
|
||||
};
|
||||
|
||||
|
||||
fixture = await loadFixture({
|
||||
root: './fixtures/static build/',
|
||||
});
|
||||
|
@ -158,8 +157,11 @@ describe('Static build', () => {
|
|||
|
||||
it('warns when accessing headers', async () => {
|
||||
let found = false;
|
||||
for(const log of logs) {
|
||||
if(log.type === 'ssg' && /[hH]eaders are not exposed in static-site generation/.test(log.args[0])) {
|
||||
for (const log of logs) {
|
||||
if (
|
||||
log.type === 'ssg' &&
|
||||
/[hH]eaders are not exposed in static-site generation/.test(log.args[0])
|
||||
) {
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue