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 async(req, res) => {
const url = req.url.replace('/ssr', '').replace(/^\//, '')
if (url === '') {
const routes = Object.keys(users)
const route = routes[(Math.random() * routes.length) | 0]
res.setHeader('Location', `/${route}`)
res.status(302).send('')
return
}
if (!users.hasOwnProperty(url)) {
res.status(404).send('not found')
return
}
try {
const scope = await fork(app, {
start: startServer,
ctx: users[url],
})
const data = serialize(scope)
const content = renderToString(React.createElement(App, {root: scope}))
const result = await compile({content, data})
res.send(result)
} catch (err) {
console.error(err)
res.status(500).send('something going wrong')
}
}