Created
December 8, 2018 15:39
-
-
Save talentlessguy/6c6ef3bd85cc08852fec71192aded7c5 to your computer and use it in GitHub Desktop.
NextJS config doesn't work
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 sass = require('@zeit/next-sass'); | |
const getRoutes = require('./routes'); | |
module.exports = sass(); | |
module.exports = { | |
exportPathMap: getRoutes | |
} |
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
module.exports = () => { | |
return { | |
'/': { page: '/' }, | |
'/404': { page: '/404' }, | |
'/about': { page: '/about' }, | |
'/p': {page: '/post'} | |
} | |
} |
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 express = require('express'); | |
const next = require('next'); | |
const { parse } = require('url'); | |
const dev = process.env.NODE_ENV !== 'production'; | |
const PORT = process.env.PORT || 3000; | |
const app = next({dir: '.', dev }); | |
const handle = app.getRequestHandler(); | |
const getRoutes = require('./routes'); | |
const routes = getRoutes(); | |
app.prepare().then(() => { | |
const server = express(); | |
server.get('*', (req, res) => { | |
const parsedUrl = parse(req.url, true); | |
const { pathname, query = {} } = parsedUrl; | |
const route = routes[pathname]; | |
if (route) { | |
return app.render(req, res, route.page, query); | |
} | |
return handle(req, res); | |
}); | |
server.listen(PORT, err => { | |
if (err) throw err; | |
console.log(`> Ready on http://localhost:${PORT}`); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment