Skip to content

Instantly share code, notes, and snippets.

@ianwcarlson
Created December 26, 2018 00:14
Show Gist options
  • Save ianwcarlson/6af7476a8c1fe0b2a2e5fba5842f4d35 to your computer and use it in GitHub Desktop.
Save ianwcarlson/6af7476a8c1fe0b2a2e5fba5842f4d35 to your computer and use it in GitHub Desktop.
// 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