2018-02-20 02:35:31 +02:00
|
|
|
const get = require('lodash.get');
|
|
|
|
const Document = require('hapi-render-react-joyent-document');
|
|
|
|
const path = require('path');
|
|
|
|
const url = require('url');
|
|
|
|
|
2018-02-27 12:59:15 +02:00
|
|
|
const { theme } = require('joyent-ui-toolkit');
|
2018-02-20 02:35:31 +02:00
|
|
|
const { default: createClient } = require('./state/apollo-client');
|
|
|
|
const { default: createStore } = require('./state/redux-store');
|
|
|
|
|
|
|
|
const indexFile = path.join(__dirname, '../../build/index.html');
|
|
|
|
|
|
|
|
const getState = request => {
|
2018-02-26 18:42:25 +02:00
|
|
|
const { req } = request.raw;
|
2018-02-20 02:35:31 +02:00
|
|
|
|
|
|
|
const _font = get(theme, 'font.href', () => '');
|
|
|
|
const _mono = get(theme, 'monoFont.href', () => '');
|
|
|
|
const _addr = url.parse(`http://${req.headers.host}`);
|
|
|
|
const _theme = Object.assign({}, theme, {
|
|
|
|
font: Object.assign({}, theme.font, {
|
|
|
|
href: () => _font(_addr)
|
|
|
|
}),
|
|
|
|
monoFont: Object.assign({}, theme.monoFont, {
|
|
|
|
href: () => _mono(_addr)
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
theme: _theme,
|
|
|
|
createClient,
|
|
|
|
createStore
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = Document({ indexFile, getState });
|