2017-02-04 104 views
2

我已经试过了所有的东西。 我有一个非常简单的ng2应用程序。这是文件的结构:用角度2 cli表示

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然后导航到本地主机: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) 

但意味着> client> dist文件夹中包含所有js文件。任何想法?

回答

4

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

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

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

天才要比!这解决了问题。谢谢 –

+0

@GastonK你应该接受这个答案,因为它解决了问题。 –

+0

完成@LajosArpad! –