Created
August 31, 2020 18:53
-
-
Save trycatchfinallydev/b556879a6a22f3b483454e47c74bae03 to your computer and use it in GitHub Desktop.
NextJS Custom Server definition for use with Heroku NGINX buildpack
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 { createServer } = require('http') | |
const { parse } = require('url') | |
const next = require('next') | |
const fs = require('fs'); | |
const dev = process.env.NODE_ENV !== 'production' | |
const app = next({ dev }) | |
const handle = app.getRequestHandler() | |
app.prepare().then(() => { | |
createServer((req, res) => { | |
const parsedUrl = parse(req.url, true) | |
handle(req, res, parsedUrl) | |
}).listen('/tmp/nginx.socket', (err) => { | |
if (err) throw err | |
console.log('> NextJS Server running...') | |
fs.openSync('/tmp/app-initialized', 'w'); | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment