Created
December 26, 2018 00:14
-
-
Save ianwcarlson/6af7476a8c1fe0b2a2e5fba5842f4d35 to your computer and use it in GitHub Desktop.
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
// This file doesn't go through babel or webpack transformation. | |
// Make sure the syntax and sources this file requires are compatible with the current node version you are running | |
// See https://github.com/zeit/next.js/issues/1245 for discussions on Universal Webpack or universal Babel | |
const { createServer } = require('http') | |
const express = require('express') | |
const { parse } = require('url') | |
const next = require('next') | |
const path = require('path'); | |
const dev = process.env.NODE_ENV !== 'production' | |
const app = next({ dev }) | |
const handle = app.getRequestHandler() | |
const executiveReportConfig = require('./pages/executiveReport/config'); | |
const configMap = { | |
executiveReport: executiveReportConfig, | |
}; | |
app.prepare().then(() => { | |
const server = express() | |
server.get('/:subject/config', (req, res) => { | |
const subject = req.params.subject; | |
return res.json(configMap[subject]); | |
}) | |
server.get('/:subject/:page', (req, res) => { | |
return app.render(req, res, `/${req.params.subject}/${req.params.page}`, { | |
...req.query, | |
page: req.params.page | |
}) | |
}) | |
server.get('*', (req, res) => { | |
handle(req, res) | |
}) | |
server.listen(3000) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment