Skip to content

Instantly share code, notes, and snippets.

@ryanbelke
Last active October 21, 2018 02:14
Show Gist options
  • Select an option

  • Save ryanbelke/87f4f9d7fefe323fdbe19864c48aef86 to your computer and use it in GitHub Desktop.

Select an option

Save ryanbelke/87f4f9d7fefe323fdbe19864c48aef86 to your computer and use it in GitHub Desktop.
/* server.js */
const express = require('express')
const next = require('next')
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()
app.prepare()
.then(() => {
const server = express()
server.get('/restaurants/:id', (req, res) => {
const actualPage = '/restaurants'
const queryParams = { id: req.params.id }
console.dir("req.params.id = " + JSON.stringify(req.params.id))
app.render(req, res, actualPage, queryParams)
})
server.get('*', (req, res) => {
return handle(req, res)
})
server.listen(3000, (err) => {
if (err) throw err
console.log('> Ready on http://localhost:3000')
})
})
.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