import cookieParser = require('cookie-parser'); import serialize from 'serialize-javascript'; import express from 'express'; import { StaticRouter } from 'inferno-router'; import { renderToString } from 'inferno-server'; import { matchPath } from 'inferno-router'; import path = require('path'); import { App } from '../shared/components/app'; import { routes } from '../shared/routes'; import IsomorphicCookie from 'isomorphic-cookie'; const server = express(); const port = 1234; server.use(express.json()); server.use(express.urlencoded({ extended: false })); server.use('/assets', express.static(path.resolve('./dist/assets'))); server.use('/static', express.static(path.resolve('./dist/client'))); server.use(cookieParser()); server.get('/*', (req, res) => { const activeRoute = routes.find(route => matchPath(req.url, route)) || {}; console.log(activeRoute); const context = {} as any; const isoData = { name: 'fishing sux', }; let auth: string = IsomorphicCookie.load('jwt', req); const wrapper = ( ); if (context.url) { return res.redirect(context.url); } res.send(`
${renderToString(wrapper)}
`); }); let Server = server.listen(port, () => { console.log(`http://localhost:${port}`); }); /** * Used to restart server by fuseBox */ export async function shutdown() { Server.close(); Server = undefined; }