[英]Setting up MEAN stack not rendering app-root
I'm trying to setup a basic mean stack by following this guide , but the client doesn't seem to render the app instead the body contains, 我正在尝试按照本指南设置基本的均值堆栈,但是客户端似乎并没有呈现该应用程序,而是主体包含了该内容,
<body>
<app-root></app-root>
</body>
The file structure is exactly the same as a blank angular cli project except the addition of two extra files. 除了增加了两个额外的文件外 ,文件结构与空白的 cli项目完全相同 。
PLUS: npm install --save ejs cors express body-parser
npm install --save ejs cors express body-parser
: npm install --save ejs cors express body-parser
routes/index.js 路线/ index.js
var express = require('express');
var router = express.Router();
router.get('/', function(req, res, next) {
res.render('index.html');
});
module.exports = router;
server.js server.js
var express = require('express');
var path = require('path');
var bodyParser = require('body-parser');
var cors = require('cors')
var index = require('./routes/index');
// app
var app = express();
// cors
app.use(cors());
// views
app.set('views', path.join(__dirname, 'src'));
// engine
app.set('view enginer', 'ejs');
app.engine('html', require('ejs').renderFile);
// angular dist
app.use(express.static(__dirname + '/dist'));
// body bodyParser
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
// route
app.use('/', index);
// Initialize the app.
var server = app.listen(process.env.PORT || 3000, function () {
var port = server.address().port;
console.log("App now running on port", port);
});
I run an ng build
and node server.js
but get a blank white page in the browser. 我运行
ng build
和node server.js
但在浏览器中出现空白页面。
Perhaps there is a breaking change that I'm not aware of since that guide was using angular2 (I'm using angular 6). 也许有一个重大的变化,我不知道,因为该指南使用的是angular2(我使用的是Angle 6)。
Since your index.html
isn't directly inside the dist
folder (rather, it is inside a sub-folder for some reason), try changing app.use(express.static(__dirname + '/dist'));
由于您的
index.html
不在dist
文件夹内(而是出于某种原因,它位于子文件夹内),因此请尝试更改app.use(express.static(__dirname + '/dist'));
to app.use(express.static(__dirname + '/dist/<your project name here>'));
到
app.use(express.static(__dirname + '/dist/<your project name here>'));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.