Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
app.use((req, res, next) => {
const css = [];
const networkLayer = new Relay.DefaultNetworkLayer(GRAPHQL_URL, {
headers: {
cookie: req.headers.cookie,
},
});
match({ routes, location: req.url }, (err, redirectLocation, renderProps) => {
if (err) {
// return res.status(500).end('Internal server error');
next(err);
}
if (redirectLocation) {
return res.redirect(redirectLocation.pathname + redirectLocation.search);
}
if (!renderProps) {
return res.status(404).end('Not found.');
}
const render = function render({ data, props }) {
const userAgent = req.headers['user-agent'];
const InitialComponent = (
return new Promise((resolve, reject) => {
match({routes, history, location}, (error, redirectLocation, renderProps) => {
if (error) {
return reject(error);
}
if (redirectLocation) {
return resolve({
redirectLocation
});
}
if (history) { // only on client side
renderProps.history = history;
}
function resolveWithComponent() {
const component = (
export function match(routes, location, store, cb) { // eslint-disable-line import/prefer-default-export
reactRouterMatch({ history: createMemoryHistory(), routes, location }, cb);
}
export default function isomorphicRender(req, res) {
const location = createLocation(req.url);
const authStatus = req.isAuthenticated();
const store = configureStore({
api: {
url: process.env.API_URL
},
login: {
loggedIn: authStatus,
loginRequest: false,
loginError: ''
}
});
match({
routes: getRoutes(store),
location
}, function(err, redirectLocation, renderProps) {
if (err) {
console.error(err);
return res.status(500).end('Internal server error');
}
if (redirectLocation) {
return res.redirect(302, redirectLocation.pathname + redirectLocation.search);
}
if (!renderProps) {
return res.status(404).end('Not found...');
}
export default function render(
req: Request,
res: Response,
next: NextFunction
): void {
const history = createMemoryHistory({
entries: [req.url]
});
const routes = createRoutes();
match({ history, routes }, (error, redirectLocation, renderProps) => {
if (error) {
return next(error);
} else if (redirectLocation) {
return res
.status(302)
.redirect(redirectLocation.pathname + redirectLocation.search);
} else if (renderProps) {
res.status(200);
res.write("");
res.write(createPage(req, res, renderProps));
return res.end();
}
return res.status(404).send("not-found");
});
}
return new Promise((resolve, reject) => {
match(options, (error, redirectLocation, renderProps) => {
if (error) reject(error);
else resolve({ redirectLocation, renderProps });
});
});
}
.use(function renderApp(req, res) {
match({ routes, location: req.url }, (error, redirectLocation, renderProps) => {
if (error) {
res.status(500).send(error.message)
} else if (redirectLocation) {
res.redirect(302, redirectLocation.pathname + redirectLocation.search)
} else if (renderProps) {
let wrap = require('../demo/pages/BasePage.txt')
.replace(/\$\{cssBundlePath\}/g, '')
.replace(/\$\{jsBundlePath\}/g, 'http://localhost:8082/assets/bundle.js');
res.status(200).send(wrap);
} else {
res.status(404).send('Not found')
}
});
export function boot(routes: Route): void {
match({routes, history}, (err, redirect, props) => {
if (err) {
throw err;
} else if (redirect) {
invariant(false, 'Redirects are not supported');
} else {
render(
,
document.getElementById(HOST_ELEMENT)
);
}
});
}
);
const html = renderToString(
);
return res.send(`${html}`);
}).catch(() => {
return next();
});
} else {
next();
}
};
match(matchOpts, handleMatchResult);
}