我已经构建了Angular通用应用程序,它具有dist.ands服务器和server.js以及node_modules文件夹。
当我运行node server.js
时,我能够加载应用程序但是当我使用IIS NOde在IIS中部署时,我只获得index.html,CSS和JS文件未加载
'use strict';
require('zone.js/dist/zone-node');
require('reflect-metadata');
const express = require('express');
const ngUniversal = require('@nguniversal/express-engine');
const { provideModuleMap } = require('@nguniversal/module-map-ngfactory-loader');
const { AppServerModuleNgFactory, LAZY_MODULE_MAP } = require('./dist-server/main.bundle');
function angularRouter(req, res) {
// Only 1st time we are getting request here --1
and log will be my Virtual APP directory Name
console.log(req.url);
res.render('index', {req, res});
}
const app = express();
app.engine('html', ngUniversal.ngExpressEngine({
bootstrap: AppServerModuleNgFactory,
providers: [
provideModuleMap(LAZY_MODULE_MAP)
]
}));
app.set('view engine', 'html');
app.set('views', 'dist');
app.get('/', angularRouter);
app.use(express.static(`${__dirname}/dist`));
app.get('*', angularRouter);
app.listen(process.env.PORT, () => {
// console.log('Listening on port 3000');
});
我在web.config中尝试了不同的URL重写规则,但它不起作用,因为一旦加载了index.html,那么所有请求都通过express发送,所以表达我无法计算从IIS
路由时如何使用静态文件注意:当我运行节点server.js,即在localhost上监听应用程序时,应用程序工作正常:3000