Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
//fetch,
// The twins below are wild, be careful!
pathname: req.path,
query: req.query
};
const route = await router.resolve(context);
if (route.redirect) {
res.redirect(route.status || 302, route.redirect);
return;
}
const data = { ...route };
const obj = Omi.renderToString(route.component, {}, { data: route.data })
const scripts = new Set();
const addChunk = chunk => {
if (chunks[chunk]) {
chunks[chunk].forEach(asset => scripts.add(asset));
} else if (__DEV__) {
throw new Error(`Chunk with name '${chunk}' cannot be found`);
}
};
addChunk('client');
if (route.chunk) addChunk(route.chunk);
if (route.chunks) route.chunks.forEach(addChunk);
data.scripts = Array.from(scripts);
data.app = {
app.get('/', function (req, res) {
const obj = Omi.renderToString()
res.end(`
<title>Omi SSR</title>
${obj.css.join('')}
${obj.html}
`)
})
if (route.chunks) route.chunks.forEach(addChunk);
data.scripts = Array.from(scripts);
data.app = {
apiUrl: config.api.clientUrl,
};
if (route.data) {
data.scriptData = 'var __data = ' + JSON.stringify(route.data)
}
data.children = obj.html
data.css = obj.css
//const html = ReactDOM.renderToStaticMarkup();
//const html = ReactDOM.renderToStaticMarkup(<div>);
const resutl = Omi.renderToString()
res.status(route.status || 200);
res.send(`${resutl.html}`);
} catch (err) {
next(err);
}
});
</div>