2018-04-18 21:01:26 +02:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var _react = _interopRequireDefault(require("react"));
|
|
|
|
|
|
|
|
var _server = require("react-dom/server");
|
|
|
|
|
|
|
|
var _redux = require("redux");
|
|
|
|
|
|
|
|
var _reactRedux = require("react-redux");
|
|
|
|
|
|
|
|
var _reactRouterDom = require("react-router-dom");
|
|
|
|
|
2018-05-23 20:16:47 +02:00
|
|
|
var _reducers = _interopRequireDefault(require("@reducers"));
|
2018-05-23 10:18:50 +02:00
|
|
|
|
2018-05-23 20:16:47 +02:00
|
|
|
var _GAListener = _interopRequireDefault(require("@components/GAListener"));
|
2018-05-23 10:18:50 +02:00
|
|
|
|
2018-05-23 20:16:47 +02:00
|
|
|
var _app = _interopRequireDefault(require("@app"));
|
2018-04-18 21:01:26 +02:00
|
|
|
|
2018-04-18 21:11:25 +02:00
|
|
|
var _renderFullPage = _interopRequireDefault(require("../renderFullPage.js"));
|
2018-04-18 21:01:26 +02:00
|
|
|
|
|
|
|
var _reactHelmet = _interopRequireDefault(require("react-helmet"));
|
|
|
|
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
|
2018-06-06 04:34:24 +02:00
|
|
|
var siteConfig = require('@config/siteConfig');
|
2018-05-02 20:52:19 +02:00
|
|
|
|
2018-04-18 21:01:26 +02:00
|
|
|
module.exports = function (req, res) {
|
|
|
|
var context = {}; // customize the reducer by passing in intial state configs
|
|
|
|
|
2018-05-23 10:18:50 +02:00
|
|
|
var MyReducers = (0, _reducers.default)(siteConfig);
|
|
|
|
var MyApp = _app.default;
|
|
|
|
var MyGAListener = (0, _GAListener.default)(siteConfig); // create a new Redux store instance
|
2018-04-18 21:01:26 +02:00
|
|
|
|
|
|
|
var store = (0, _redux.createStore)(MyReducers); // render component to a string
|
|
|
|
|
|
|
|
var html = (0, _server.renderToString)(_react.default.createElement(_reactRedux.Provider, {
|
|
|
|
store: store
|
|
|
|
}, _react.default.createElement(_reactRouterDom.StaticRouter, {
|
|
|
|
location: req.url,
|
|
|
|
context: context
|
|
|
|
}, _react.default.createElement(MyGAListener, null, _react.default.createElement(MyApp, null))))); // get head tags from helmet
|
|
|
|
|
|
|
|
var helmet = _reactHelmet.default.renderStatic(); // check for a redirect
|
|
|
|
|
|
|
|
|
|
|
|
if (context.url) {
|
|
|
|
// Somewhere a `<Redirect>` was rendered
|
|
|
|
return res.redirect(301, context.url);
|
|
|
|
} else {} // we're good, send the response
|
|
|
|
// get the initial state from our Redux store
|
|
|
|
|
|
|
|
|
|
|
|
var preloadedState = store.getState(); // send the rendered page back to the client
|
|
|
|
|
|
|
|
res.send((0, _renderFullPage.default)(helmet, html, preloadedState));
|
|
|
|
};
|