diff --git a/src/server/ssr/index.js b/src/server/ssr/index.js index 2eaab23b..1940a3f3 100644 --- a/src/server/ssr/index.js +++ b/src/server/ssr/index.js @@ -3,9 +3,9 @@ * @desc */ import React from 'react' -import {readFileSync, readFile} from 'fs' +import {readFileSync} from 'fs' // readFile import path from 'path' -import _ from 'lodash' +// import _ from 'lodash' import {sync as globSync} from 'glob' import {renderToString} from 'react-dom/server' import {ServerStyleSheet, StyleSheetManager} from 'styled-components' @@ -14,7 +14,6 @@ import {configureRootComponent, configureApp} from 'common/app' import HtmlComponent from './HtmlComponent' import assets from 'webpack-assets' import faviconsAssets from 'favicons-assets' - import type {Node} from 'react' const translations = globSync('locals/*.json') @@ -33,7 +32,7 @@ export default (req: express$Request, res: express$Response) => { const initialState: Object = isLoggedIn ? {me: {auth: {isLoggedIn, token}}} : {} - const localeData = require('react-intl/locale-data/' + lang) + const localeData = require('react-intl/locale-data/' + (lang || 'en')) const i18n = { lang, localeData, @@ -68,49 +67,6 @@ export default (req: express$Request, res: express$Response) => { App } - Object.keys(assets).map(key => { - const bundle = assets[key] - Object.keys(bundle).map(async filetype => { - const filename = bundle[filetype] - const isJS = filetype === 'js' - const isCSS = filetype === 'css' - - var stream = res.push(filename, { - status: 200, // optional - method: 'GET', // optional - request: { - accept: '*/*' - }, - response: { - 'content-type': isJS - ? 'application/javascript' - : isCSS ? 'text/css' : 'text/html' - } - }) - - const readFileAsync = path => { - return new Promise((resolve, reject) => { - try { - readFile(path, (err, data) => { - if (err) { - reject(err) - } - resolve(data) - }) - } catch (e) { - reject(e) - } - }) - } - - const memoizedReadFileAsync = _.memoize(readFileAsync) - const dataToStream = await memoizedReadFileAsync( - `${process.env.CLIENT_DIST_PATH}/${filename}` - ) - stream.end(dataToStream) - }) - }) - const html: string = HtmlComponent(props) res.send(html) } diff --git a/src/server/ssr/server_push.wip.js b/src/server/ssr/server_push.wip.js new file mode 100644 index 00000000..040460b6 --- /dev/null +++ b/src/server/ssr/server_push.wip.js @@ -0,0 +1,42 @@ +// Object.keys(assets).map(key => { +// const bundle = assets[key] +// Object.keys(bundle).map(async filetype => { +// const filename = bundle[filetype] +// const isJS = filetype === 'js' +// const isCSS = filetype === 'css' +// +// var stream = res.push(filename, { +// status: 200, // optional +// method: 'GET', // optional +// request: { +// accept: '*/*' +// }, +// response: { +// 'content-type': isJS +// ? 'application/javascript' +// : isCSS ? 'text/css' : 'text/html' +// } +// }) +// +// const readFileAsync = path => { +// return new Promise((resolve, reject) => { +// try { +// readFile(path, (err, data) => { +// if (err) { +// reject(err) +// } +// resolve(data) +// }) +// } catch (e) { +// reject(e) +// } +// }) +// } +// +// const memoizedReadFileAsync = _.memoize(readFileAsync) +// const dataToStream = await memoizedReadFileAsync( +// `${process.env.CLIENT_DIST_PATH}/${filename}` +// ) +// stream.end(dataToStream) +// }) +// })