Express服务器未部署angular 8应用

时间:2019-12-16 16:42:23

标签: angular express mean-stack

enter image description here我正在学习构建一个简单的均值堆栈应用程序。我有默认的角度项目,可以正常运行。我想通过快递服务器运行angular应用程序,但在浏览器中显示错误“ Cannot GET /”。 这是我的代码:

    const express = require("express");
const compression = require("compression");

const _port = 4100;
const _app_folder = 'src/dist/app';

const app = express();
app.use(compression());


// ---- SERVE STATIC FILES ---- //
app.get('*.*', express.static(_app_folder, {maxAge: '1y'}));

// ---- SERVE APLICATION PATHS ---- //
app.all('*', function (req, res) {
    res.status(200).sendFile('/', {root: _app_folder});
});

// ---- START UP THE NODE SERVER  ----
app.listen(_port, function () {
    console.log("Node Express server for " + app.name + " listening on http://localhost:" + _port);
});

0 个答案:

没有答案