問題 - 我不能得到任何響應郵遞員時,本地主機:9000。它應該給我一個用戶JSON回來,這是在我的路線文件只有暫時。相反,它吐出以下內容。安裝創建反應應用程序與快遞
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<script type="text/javascript" src="/static/js/main.ce2f0561.js"></script>
</body>
設置
使用create反應的應用程式內Express連接。
我的文件夾結構是
--src React app lives in this
--server
- index.js
- express.js
- 控制器
- 路線
個-- rs_notes.js
rs_routes.js
'use strict';
module.exports = function(router){
const notesController = require('../controllers/cs_notes');
router.route('/', function(req, res, next) {
// Comment out this line:
//res.send('respond with a resource');
// And insert something like this instead:
res.json([{
id: 1,
username: "samsepi0l"
}, {
id: 2,
username: "D0loresH4ze"
}]);
});
};
express.js
const express = require('express');
const morgan = require('morgan');
const path = require('path');
const app = express();
const router = express.Router();
// Setup logger
app.use(morgan(':remote-addr - :remote-user [:date[clf]] ":method :url HTTP/:http-version" :status :res[content-length] :response-time ms'));
// Serve static assets
app.use(express.static(path.resolve(__dirname, '..', 'build')));
require('./routes/rs_notes')(router);
// Always return the main index.html, so react-router render the route in the client
router.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, '..', 'build', 'index.html'));
});
module.exports = app;
index.js
'use strict';
const app = require('./express');
const PORT = process.env.PORT || 9000;
app.listen(PORT,() => {
console.log(`App listening on port ${PORT}!`);
});
整個項目鏈接 - https://drive.google.com/file/d/0B35OQMkRo3KcSHlkeXdWVjVjc0U/view?usp=sharing
我的問題或懷疑是
- 我是通過路由器在一個正確的方式。我們以前在表達4之前通過這個 的方式傳遞應用程序?所以不知道這裏是否有相同的結構。
- 我可以通過點擊localhost:9000(服務器由配置的節點服務器命令運行)而不是郵遞員在瀏覽器中加載它。
這是HTML服務,還是你看到這是文本?前者對我來說似乎沒問題。 – idmean
它在瀏覽器中工作嗎? – Colin
堅持....我無意中提交了它......讓我編輯並正確詢問 – kushalvm