表达角度为2 cli

时间:2017-02-04 10:55:00

标签: javascript angular express server

我已经尝试过所有的东西。 我有一个非常简单的ng2应用程序。这是文件结构:

mean
  |- client (where the ng2 app lives)
  | |- dist
  | |- (all ng2 app folders)...
  |- node_modules
  |- routes
  | |- index.js
  |- views
  |- package.json
  |- server.js

index.js:

var express = require('express');
var router = express.Router();

router.get('/', (req, res, next) => {
    res.render('../client/dist/index.html')
})

module.exports = router;

当我运行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)

但意思是>客户> dist文件夹包含所有js文件。有什么想法吗?

1 个答案:

答案 0 :(得分:5)

您需要提供静态文件夹../client/dist

app.use(express.static(path.join(__dirname, 'client/dist')))

app.route('/*', (req, res, next) {
  // do something
});