将角度构建“ dist”文件添加到节点js server.js

时间:2020-04-03 02:13:50

标签: node.js angular express heroku mean-stack

我正在尝试将我的MEAN堆栈应用程序部署到heroku。我已成功提交了该应用程序,但似乎无法将ng build“ dist”文件连接到server.js文件。

这是我尝试添加文件的server.js代码:

var distDir = __dirname + "/dist/";

app.use(express.static(distDir));

1 个答案:

答案 0 :(得分:0)

尝试一下:

@PersistenceContext

const path = require('path'); const express = require('express'); const app = express(); // Serve static files app.use(express.static(__dirname + '/outputPath')); // Send all requests to index.html app.get('/*', function(req, res) { res.sendFile(path.join(__dirname + '/outputPath/index.html')); }); // default Heroku port app.listen(process.env.PORT || 5000) outputPathoutputPath文件中的值(项目->架构师->构建->选项-> outputPath)。