Skip to content

Commit

Permalink
feat(netlify): emit server.js to leverage native esm (#401)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 authored Aug 9, 2022
1 parent 88d9352 commit 8304ae2
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/presets/netlify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ export const netlify = defineNitroPreset({
contents = currentRedirects + '\n' + contents
}
await fsp.writeFile(redirectsPath, contents)

const serverCJSPath = join(nitro.options.output.serverDir, 'server.js')
const serverJSCode = `
let _handler
exports.handler = function handler (event, context) {
if (_handler) {
return _handler(event, context)
}
return import('./server.mjs').then(m => {
_handler = m.handler
return _handler(event, context)
})
}
`.trim()
await fsp.writeFile(serverCJSPath, serverJSCode)
}
}
})
Expand Down

0 comments on commit 8304ae2

Please sign in to comment.