我当前的 server.js:
let express = require('express');
let harp = require('harp');
let path = require('path');
let app = express();
app.use(express.static(__dirname + "/dist"));
app.use(harp.mount(__dirname + "/dist"));
let port = process.env.PORT || 3333;
app.listen(port, () => console.log("Listening on port " + port) );
// ... other routes for data fetching ...
// For browserHistory: https://github.com/reactjs/react-router/blob/1.0.x/docs/guides/basics/Histories.md
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'dist', 'index.html'));
});
当我在mysite.com/
. 但是,如果我输入mySite.com/someRoute
,它会中断。具体来说,我在控制台中看到以下内容:
Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://localhost:3333/dashboards/styles/normalize-3.0.3.min.css".
...
Uncaught SyntaxError: Unexpected token <
...
我的理解是,为了解决这个问题,我还需要实现服务器端渲染。那是准确的吗?如果是这样,那么所需的最低设置是什么?我看过的所有指南都比我现在想要的要深入得多。
(如果有帮助,我可以升级依赖项。)react: 0.14.7 react-router: 1.0.3