I'm trying to understand react-dom/server.
I have a react application, using express as the server.
I have an express route like so :
var server = app.listen(3000);
app.get('/test', (req, res) => {
const context = {}
const html = ReactDOMServer.renderToString(
<h1>foo</h1>
)
if (context.url) {
res.writeHead(302, {
Location: context.url
})
res.end()
} else {
res.write(html)
res.end()
}
});
If I run the server file with node app-server
, I get this error :
<h1>adasd</h1>
^
SyntaxError: Unexpected token <
I passed JSX to renderToString based on the example there : https://github.com/ReactTraining/react-router/blob/master/packages/react-router/docs/api/StaticRouter.md
How can I make the express server file processed this JSX code ?
For the client side, I use webpack with the babel loader, and it works fine.