Gas*_*n K 2 javascript express server angular
我已经尝试了一切.我有一个非常简单的ng2应用程序.这是文件结构:
mean
|- client (where the ng2 app lives)
| |- dist
| |- (all ng2 app folders)...
|- node_modules
|- routes
| |- index.js
|- views
|- package.json
|- server.js
Run Code Online (Sandbox Code Playgroud)
index.js:
var express = require('express');
var router = express.Router();
router.get('/', (req, res, next) => {
res.render('../client/dist/index.html')
})
module.exports = router;
Run Code Online (Sandbox Code Playgroud)
当我运行server.js并导航到localhost:3000时,脚本只是不加载:
Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost:3000/inline.bundle.js Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost:3000/vendor.bundle.js Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost:3000/main.bundle.js Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost:3000/styles.bundle.css Failed to load resource: the server responded with a status of 404 (Not Found)
Run Code Online (Sandbox Code Playgroud)
但是mean> client> dist文件夹包含所有js文件.任何的想法?
你需要服务静态文件夹 ../client/dist
app.use(express.static(path.join(__dirname, 'client/dist')))
app.route('/*', (req, res, next) {
// do something
});
Run Code Online (Sandbox Code Playgroud)