Skip to content

Instantly share code, notes, and snippets.

@ernestofreyreg
Created May 24, 2017 01:05
Show Gist options
  • Save ernestofreyreg/dafdf7ec727875f2af728a5d975b384d to your computer and use it in GitHub Desktop.
Save ernestofreyreg/dafdf7ec727875f2af728a5d975b384d to your computer and use it in GitHub Desktop.
SSR React on Google Cloud Functions
const next = require('next')
const app = next({ dev: false })
const handle = app.getRequestHandler()
const slasher = handler => (req, res) => {
if (req.url === '') {
req.url = '/'
}
return handler(req, res)
}
module.exports.handler = slasher((req, res) => {
return app.prepare()
.then(() => handle(req, res))
.catch(ex => {
console.error(ex.stack)
process.exit(1)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment