[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',
|
method = 'GET',
|
||||||
body = undefined,
|
body = undefined,
|
||||||
logging,
|
logging,
|
||||||
ssr
|
ssr,
|
||||||
}: CreateRequestOptions): Request {
|
}: CreateRequestOptions): Request {
|
||||||
let headersObj =
|
let headersObj =
|
||||||
headers instanceof Headers
|
headers instanceof Headers
|
||||||
|
@ -52,20 +52,21 @@ export function createRequest({
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if(!ssr) {
|
if (!ssr) {
|
||||||
// Warn when accessing headers in SSG mode
|
// Warn when accessing headers in SSG mode
|
||||||
const _headers = request.headers;
|
const _headers = request.headers;
|
||||||
const headersDesc = Object.getOwnPropertyDescriptor(request, 'headers') || {};
|
const headersDesc = Object.getOwnPropertyDescriptor(request, 'headers') || {};
|
||||||
Object.defineProperty(request, 'headers', {
|
Object.defineProperty(request, 'headers', {
|
||||||
...headersDesc,
|
...headersDesc,
|
||||||
get() {
|
get() {
|
||||||
warn(logging,
|
warn(
|
||||||
|
logging,
|
||||||
'ssg',
|
'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.`
|
`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 _headers;
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return request;
|
return request;
|
||||||
|
|
|
@ -176,7 +176,7 @@ async function handleRequest(
|
||||||
method: req.method,
|
method: req.method,
|
||||||
body,
|
body,
|
||||||
logging,
|
logging,
|
||||||
ssr: buildingToSSR
|
ssr: buildingToSSR,
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -22,12 +22,11 @@ describe('Static build', () => {
|
||||||
dest: {
|
dest: {
|
||||||
write(chunk) {
|
write(chunk) {
|
||||||
logs.push(chunk);
|
logs.push(chunk);
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
level: 'warn',
|
level: 'warn',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
fixture = await loadFixture({
|
fixture = await loadFixture({
|
||||||
root: './fixtures/static build/',
|
root: './fixtures/static build/',
|
||||||
});
|
});
|
||||||
|
@ -158,8 +157,11 @@ describe('Static build', () => {
|
||||||
|
|
||||||
it('warns when accessing headers', async () => {
|
it('warns when accessing headers', async () => {
|
||||||
let found = false;
|
let found = false;
|
||||||
for(const log of logs) {
|
for (const log of logs) {
|
||||||
if(log.type === 'ssg' && /[hH]eaders are not exposed in static-site generation/.test(log.args[0])) {
|
if (
|
||||||
|
log.type === 'ssg' &&
|
||||||
|
/[hH]eaders are not exposed in static-site generation/.test(log.args[0])
|
||||||
|
) {
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue