Skip to content

Commit

Permalink
[ci] format
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewp authored and actions-user committed Apr 7, 2022
1 parent 7e9d82d commit c3b083f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
11 changes: 6 additions & 5 deletions packages/astro/src/core/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function createRequest({
method = 'GET',
body = undefined,
logging,
ssr
ssr,
}: CreateRequestOptions): Request {
let headersObj =
headers instanceof Headers
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/vite-plugin-astro-server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ async function handleRequest(
method: req.method,
body,
logging,
ssr: buildingToSSR
ssr: buildingToSSR,
});

try {
Expand Down
10 changes: 6 additions & 4 deletions packages/astro/test/static-build.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ describe('Static build', () => {
dest: {
write(chunk) {
logs.push(chunk);
}
},
},
level: 'warn',
};


fixture = await loadFixture({
root: './fixtures/static build/',
});
Expand Down Expand Up @@ -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;
}
}
Expand Down

0 comments on commit c3b083f

Please sign in to comment.