Angular Universal app with IIS Node not serving CSS Files
I have built Angular universal app which has dist and dist-server with server.js and node_modules folder.
When I run node server.js
, I'm able to load the app but when I deploy in IIS with IIS NOde , I'm only getting index.html , CSS and JS files are not loaded.
'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');
});
I have tried different URL rewrite rules in web.config but it doesn't work because once the index.html is loaded then from there all request are routed through express , so express I'm unable to figure out how to make express use static files when Routed from IIS
Note: App is working absolutely fine when I run node server.js ie app listening on localhost:3000
链接地址: http://www.djcxy.com/p/31406.html上一篇: android中的位图循环裁剪