Created
May 24, 2017 01:05
-
-
Save ernestofreyreg/dafdf7ec727875f2af728a5d975b384d to your computer and use it in GitHub Desktop.
SSR React on Google Cloud Functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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