【发布时间】:2021-01-19 19:27:29
【问题描述】:
我已将我的 Angular 项目部署到 heroku。它显示错误未找到。我尝试在节点 server.js 中运行相同的项目,同样的错误是找不到一些文件。 我试过这个https://itnext.io/how-to-deploy-angular-application-to-heroku-1d56e09c5147。 但我认为 server.js 文件中有一些错误。 服务器.js
const express = require('express');
const app = express();
const path = require('path');
const port = process.env.PORT || 4200;
const server = require('http').Server(app);
// Serve only the static files form the angularapp directory
app.use(express.static(__dirname + '/RouterApp'));
app.get('/*', function(req,res) {
res.sendFile(path.join(__dirname+'/RouterApp/index.html'));
});
// Start the app by listening on the default Heroku port
server.listen(port, function () {
console.log("App running on port " + port);
})
当我尝试将路径设置为/src/index.html 时,正在加载索引页面,但未加载 Angular 组件。
这是我的目录结构
>>RouterApp
>>...
>>server.js
>>src
>>index.html
>>components
>>...
使用node server.js 运行时遇到的错误
ENOENT:没有这样的文件或目录,stat '/data/data/com.termux/files/home/RouterApp/RouterApp/index.html'
当我尝试在localhost:4200 上运行程序时,使用ng serve 运行得非常好。
这是 GitHub 存储库https://github.com/Pradeep2898/QuoraClone
【问题讨论】: