Skip to content

Commit

Permalink
perf: avoid async/await promise wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Aug 9, 2022
1 parent 425b0c2 commit c9186a7
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/presets/netlify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,16 @@ export const netlify = defineNitroPreset({
const serverCJSPath = join(nitro.options.output.serverDir, 'server.js')
const serverJSCode = `
let _handler
exports.handler = async function handler (event, context) {
if (!_handler) {
_handler = await import('./server.mjs').then(r => r.handler)
exports.handler = function handler (event, context) {
if (_handler) {
return _handler(event, context)
}
return _handler(event, context)
return import('./server.mjs').then(m => {
_handler = m.handler
return _handler(event, context)
})
}
`.trim()
`.trim()
await fsp.writeFile(serverCJSPath, serverJSCode)
}
}
Expand Down

0 comments on commit c9186a7

Please sign in to comment.