Skip to content

Instantly share code, notes, and snippets.

@trycatchfinallydev
Created August 31, 2020 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trycatchfinallydev/b556879a6a22f3b483454e47c74bae03 to your computer and use it in GitHub Desktop.
Save trycatchfinallydev/b556879a6a22f3b483454e47c74bae03 to your computer and use it in GitHub Desktop.
NextJS Custom Server definition for use with Heroku NGINX buildpack
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