Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default (url, cb) => {
const memoryHistory = createMemoryHistory(url)
let routes = createRoutes(memoryHistory)
let location = createLocation(url)
match({ routes, location }, (error, redirectLocation, renderProps) => {
if (error) console.log('Error matching', error)
let initialData = {entities: { cars: {}, account: {} }}
const store = configureStore(initialData, memoryHistory)
// Grab the initial state from our Redux store
const finalState = store.getState()
const rootComponent = renderToString(
)
app.use((req, res, next) => {
const location = createLocation(req.path);
// Note that req.url here should be the full URL path from
// the original request, including the query string.
match({
routes,
location
}, (error, redirectLocation, renderProps) => {
if (error) {
res.status(500).send(error.message)
} else if (redirectLocation) {
res.redirect(302, redirectLocation.pathname + redirectLocation.search)
} else if (renderProps) {
renderWithData(req, res, renderProps);
} else {
next();
}
}
}
};
/* This is where the magic happens, we take the locals data we have already
fetched and seed our stores with data.
Next we use react-router to run the URL that is provided in routes.jsx
Finally we use iso in order to render this content so it picks back up
on the client side and bootstraps the stores.
init server renderer
*/
alt.bootstrap(JSON.stringify(res.locals.data || oneItemBootstraped));
try {
const location = createLocation(req.url);
match({ routes, location }, (error, redirectLocation, renderProps) => {
if (redirectLocation) {
res.redirect(301, redirectLocation.pathname + redirectLocation.search);
}
else if (error) {
res.send(500, error.message);
}
else if (renderProps == null) {
res.send(404, 'Not found');
}
else {
// alt flux flush
const content = renderToString();
iso.add(content, alt.flush());
server.get('*', (req, res, next) => {
try {
let statusCode = 200;
const data = {
title: '',
description: '',
css: '',
body: '',
debug: DEBUG,
version: PKG_VERSION
};
const css = [];
const location = createLocation(req.url);
// const history = createHistory(req.url);
match({ routes, location }, (error, redirectLocation, renderProps) => {
if (redirectLocation) {
res.redirect(301, redirectLocation.pathname + redirectLocation.search);
} else if (error) {
res.status(500).send(error.message);
} else if (renderProps === null) {
res.status(404).send('Not found');
} else {
data.title = 'DME';
// data.body = renderToString();
data.css = css.join('');
const html = ReactDOM.renderToStaticMarkup();
res.status(statusCode).send('\n' + html);
}
app.get('/*', function (req, res) {
const location = createLocation(req.url)
match({routes, location}, (err, redirectLocation, renderProps) => {
if (err) {
console.error(err)
return res.status(500).end('Internal server error')
}
if (!renderProps) {
return res.status(404).end('Not found')
}
const store = configureStore()
const InitialView = (
function handleRouting( req, res, next ) {
let location = createLocation( req.url );
let store = finalCreateStore(combinedReducers);
let childRoutes = routes( store );
match({ routes: childRoutes, location }, ( error, redirectLocation, renderProps ) => {
if ( redirectLocation ) {
return res.redirect( 301, redirectLocation.pathname + redirectLocation.search );
} else if ( error ) {
console.log( '跑來錯: ', error)
return res.status(500).send( error.message );
} else if ( renderProps == null ) {
export default function render(req, res) {
let user = {
name: 'John Smith',
dept: 'Web Team',
lastLogin: new Date(),
email: 'john@smith.com',
id: 'abcde1234'
};
const location = createLocation(req.url);
match({routes, location}, (err, redirectLocation, renderProps) => {
if (err) {
console.error(err);
return res.status(500).end('Internal server error');
}
if (!renderProps) {
return res.status(404).end('Not found');
}
const store = configureStore({user: user}, false);
const InitialView = (
app.get('/*', function (req, res) {
const location = createLocation(req.url);
match({ routes, location }, (err, redirectLocation, renderProps) => {
if(err) {
console.error(err);
return res.status(500).end('Internal server error');
}
if(!renderProps)
return res.status(404).end('Not found');
const store = configureStore();
const InitialView = (
{() =>
export default function isomorphicRender(req, res) {
const location = createLocation(req.url);
const authStatus = req.isAuthenticated();
const user = (authStatus && req.user)
? {
_id: req.user._id,
username: req.user.username,
role: (req.user.role === 0) ? 0 : 1
} : undefined;
const store = configureStore({
api: {
url: process.env.API_URL
},
login: {
loggedIn: authStatus,
loginRequest: false,
loginError: '',
/**
* Created by mikhail on 15.09.15.
*/
import React from 'react';
import router from './routing/router.js';
import createLocation from 'history/lib/createLocation';
import createBrowserHistory from 'history/lib/createBrowserHistory';
const history = createBrowserHistory();
const location = createLocation(document.location.pathname, document.location.search);
const dist = document.getElementById('app');
router(location, history)
.then((reactEl) => {
React.render(reactEl, dist);
}, (err) => {
React.render(<p>Initial render error {err}</p>, dist);
});