Код тестового сервера
const http = require('http');
const React = require('react');
const ReactDOMServer = require('react-dom/server');
const StaticRouter = require('react-router').StaticRouter;
const Express = require('express');
const app = new Express();
const server = new http.Server(app);
app.set('view engine', 'ejs');
app.use('/dist', Express.static('dist'));
app.get('*', (req, res) => {
const context = {};
const html = ReactDOMServer.renderToString(
<StaticRouter location={req.url} context={context}>
<p>test</p>
</StaticRouter>
);
if (context.url) {
res.writeHead(302, {
Location: context.url
});
res.end()
} else {
res.write(html);
res.end()
}
});
server.listen(3000, (err) => {
if (err) {
return console.error(err);
}
console.info('Server running on http://localhost:3000');
});
Ловлю такую ошибку:
\test-server.js:19
<StaticRouter location={req.url} context={context}>
^
SyntaxError: Unexpected token <
at new Script (vm.js:51:7)