-
-
Save malihassan20/d1c9880cdaf65d074c24b2f1dff58b90 to your computer and use it in GitHub Desktop.
nextJs-tour-diary-app\server.js
This file contains 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 routes = require('./routes'); | |
const { createServer } = require('http'); | |
const { parse } = require('url'); | |
const dev = process.env.NODE_ENV !== 'production'; | |
const app = next({ dev }); | |
const handle = app.getRequestHandler(); | |
const handler = routes.getRequestHandler(app); | |
app.prepare().then(() => { | |
createServer(handler, (req, res) => { | |
// Be sure to pass `true` as the second argument to `url.parse`. | |
// This tells it to parse the query portion of the URL. | |
const parsedUrl = parse(req.url, true); | |
const { pathname, query } = parsedUrl; | |
if (pathname === '/tour-detail/:tourId') { | |
app.render(req, res, '/tour-detail', query); | |
} else { | |
handle(req, res, parsedUrl); | |
} | |
}).listen(process.env.PORT || 3000, err => { | |
if (err) throw err; | |
console.log('> Ready on http://localhost:3000'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment