joyent-portal/consoles/my-joy-images/src/_document.js

58 lines
1.4 KiB
JavaScript
Raw Normal View History

const get = require('lodash.get');
const Document = require('hapi-render-react-joyent-document');
const path = require('path');
const url = require('url');
const { theme } = require('joyent-ui-toolkit');
const { default: createClient } = require('./state/apollo-client');
const { default: createStore } = require('./state/redux-store');
const indexFile = path.join(__dirname, '../../build/index.html');
2018-03-06 03:14:33 +02:00
const assets = require('../../build/asset-manifest.json');
2018-03-26 13:56:04 +03:00
const { NODE_ENV = 'development' } = process.env;
const getState = request => {
const { req } = request.raw;
2018-03-26 13:56:04 +03:00
const { headers } = req;
const { host } = headers;
2018-03-26 13:56:04 +03:00
const protocol = NODE_ENV === 'development' ? 'http:' : 'https:';
const _font = get(theme, 'font.href', () => '');
const _mono = get(theme, 'monoFont.href', () => '');
2018-03-26 13:56:04 +03:00
const _addr = url.parse(`${protocol}//${host}`);
const _theme = Object.assign({}, theme, {
font: Object.assign({}, theme.font, {
href: () =>
_font(
Object.assign(_addr, {
namespace: 'images'
})
)
}),
monoFont: Object.assign({}, theme.monoFont, {
href: () =>
_mono(
Object.assign(_addr, {
namespace: 'images'
})
)
})
});
return {
theme: _theme,
createClient,
createStore
};
};
2018-03-06 03:14:33 +02:00
module.exports = Document({
namespace: 'images/',
assets,
2018-04-24 16:17:26 +03:00
Html: require('./html'),
2018-03-06 03:14:33 +02:00
indexFile,
getState
});