Allow an adapter to export default (#3022)
* Allow an adapter to export default * Adds a changeset
This commit is contained in:
parent
c1a759b5d2
commit
8c04ff1f0b
4 changed files with 17 additions and 5 deletions
6
.changeset/forty-boats-remain.md
Normal file
6
.changeset/forty-boats-remain.md
Normal file
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
'astro': patch
|
||||
'@astrojs/vercel': patch
|
||||
---
|
||||
|
||||
Allows adapters to export default
|
|
@ -45,8 +45,14 @@ const _args = ${adapter.args ? JSON.stringify(adapter.args) : 'undefined'};
|
|||
${
|
||||
adapter.exports
|
||||
? `const _exports = adapter.createExports(_manifest, _args);
|
||||
${adapter.exports.map((name) => `export const ${name} = _exports['${name}'];`).join('\n')}
|
||||
${adapter.exports.includes('_default') ? `export default _default` : ''}
|
||||
${adapter.exports.map((name) => {
|
||||
if(name === 'default') {
|
||||
return `const _default = _exports['default'];
|
||||
export { _default as default };`;
|
||||
} else {
|
||||
return `export const ${name} = _exports['${name}'];`
|
||||
}
|
||||
}).join('\n')}
|
||||
`
|
||||
: ''
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ export function getAdapter(): AstroAdapter {
|
|||
return {
|
||||
name: '@astrojs/vercel',
|
||||
serverEntrypoint: '@astrojs/vercel/server-entrypoint',
|
||||
exports: ['_default'],
|
||||
exports: ['default'],
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ polyfill(globalThis, {
|
|||
export const createExports = (manifest: SSRManifest) => {
|
||||
const app = new App(manifest);
|
||||
|
||||
const _default = async (req: IncomingMessage, res: ServerResponse) => {
|
||||
const handler = async (req: IncomingMessage, res: ServerResponse) => {
|
||||
let request: Request;
|
||||
|
||||
try {
|
||||
|
@ -30,5 +30,5 @@ export const createExports = (manifest: SSRManifest) => {
|
|||
await setResponse(res, await app.render(request));
|
||||
};
|
||||
|
||||
return { _default };
|
||||
return { 'default': handler };
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue