Make server renderer a class
This commit is contained in:
parent
f93a980854
commit
fd2b8823e6
|
@ -2,7 +2,7 @@ import express from 'express'
|
||||||
import helmet from 'helmet'
|
import helmet from 'helmet'
|
||||||
import expressStaticGzip from 'express-static-gzip'
|
import expressStaticGzip from 'express-static-gzip'
|
||||||
import config from '../config/config.json'
|
import config from '../config/config.json'
|
||||||
import { serverRender } from './utils/serverRender'
|
import { ServerRenderer } from './utils/serverRender'
|
||||||
import { Scanner } from './utils/scanner'
|
import { Scanner } from './utils/scanner'
|
||||||
|
|
||||||
const port = process.env.PORT || 3000
|
const port = process.env.PORT || 3000
|
||||||
|
@ -29,7 +29,8 @@ app.get('/favicon.ico', (req, res) => {
|
||||||
res.status(404).send('Not Found !!!')
|
res.status(404).send('Not Found !!!')
|
||||||
})
|
})
|
||||||
|
|
||||||
app.get('*', serverRender)
|
const serverRenderer = new ServerRenderer()
|
||||||
|
app.get('*', serverRenderer.render)
|
||||||
|
|
||||||
app.listen(port, function (error) {
|
app.listen(port, function (error) {
|
||||||
if (error) {
|
if (error) {
|
||||||
|
|
|
@ -8,7 +8,13 @@ import manifest from '../../public/static/manifest.json'
|
||||||
import config from '../../config/config.json'
|
import config from '../../config/config.json'
|
||||||
import head from '../../config/head.json'
|
import head from '../../config/head.json'
|
||||||
|
|
||||||
export function serverRender (req, res, next) {
|
export class ServerRenderer {
|
||||||
|
|
||||||
|
constructor () {
|
||||||
|
console.log('ServerRenderer')
|
||||||
|
}
|
||||||
|
|
||||||
|
render (req, res, next) {
|
||||||
const activeRoute = routes.find((route) => matchPath(req.url, route)) || {}
|
const activeRoute = routes.find((route) => matchPath(req.url, route)) || {}
|
||||||
|
|
||||||
const promise = activeRoute.getData
|
const promise = activeRoute.getData
|
||||||
|
@ -24,6 +30,7 @@ export function serverRender (req, res, next) {
|
||||||
|
|
||||||
res.status(200).send(renderFullPage(markup, data))
|
res.status(200).send(renderFullPage(markup, data))
|
||||||
}).catch(next)
|
}).catch(next)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderFullPage (html, data) {
|
function renderFullPage (html, data) {
|
||||||
|
|
Loading…
Reference in New Issue