You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We are trying to set up an IISNODE server with pre-rendering using Universal.
I set up the project the following way with web.config and main server script as follows: web.config:
import 'zone.js/dist/zone-node';
import 'reflect-metadata';
import { renderModuleFactory } from '@angular/platform-server';
import { enableProdMode } from '@angular/core';
import * as express from 'express';
import { join } from 'path';
import { readFileSync } from 'fs';
import * as http from "http";
// ---------- express routes ---------
import { feedRouter } from "./routes/feed";
import { loginRouter } from "./routes/login";
import { protectedRouter } from "./routes/protected";
import { publicRouter } from "./routes/public";
import { userRouter } from "./routes/user";
import { ngExpressEngine } from '@nguniversal/express-engine';
import { provideModuleMap } from '@nguniversal/module-map-ngfactory-loader';
// ----------- normalize port ------------
function normalizePort(val): boolean | number {
const normalizedPort = parseInt(val, 10);
if (isNaN(normalizedPort)) {
// named pipe
return val;
}
if (normalizedPort >= 0) {
// port number
return normalizedPort;
}
return false;
}
// ----------- server event handlers ------------
function onError(error) {
if (error.syscall !== "listen") {
throw error;
}
const bind = typeof port === "string"
? "Pipe " + port
: "Port " + port;
// handle specific listen errors with friendly messages
switch (error.code) {
case "EACCES":
console.error(bind + " requires elevated privileges");
process.exit(1);
break;
case "EADDRINUSE":
console.error(bind + " is already in use");
process.exit(1);
break;
default:
throw error;
}
}
function onListening() {
const addr = server.address();
const bind = typeof addr === "string"
? "pipe " + addr
: "port " + addr.port;
}
// ----------- Faster server renders w/ Prod mode (dev mode never needed)------
enableProdMode();
// ============ Express app =================
const port = normalizePort(process.env.PORT || 4000);
const app = express();
const DIST_FOLDER = join(process.cwd(), 'wwwroot');
const template = readFileSync(join(DIST_FOLDER, 'browser', 'index.html')).toString();
const { AppServerModuleNgFactory, LAZY_MODULE_MAP } = require('./wwwroot/server/main.bundle');
let server;
// ---------------- ex[ress settings --------
app.set("port", port);
app.engine('html', ngExpressEngine({
bootstrap: AppServerModuleNgFactory,
providers: [
provideModuleMap(LAZY_MODULE_MAP)
]
}));
app.set('view engine', 'html');
app.set('views', join(DIST_FOLDER, 'browser'));
app.use(require('prerender-node'));
// --------------- api routes ------------
app.use("/api/secure", protectedRouter);
app.use("/api/login", loginRouter);
app.use("/api/public", publicRouter);
app.use("/api/feed", feedRouter);
app.use("/api/user", userRouter);
// Server static files from /browser
app.get('*.*', express.static(join(DIST_FOLDER, 'browser')));
// ALl regular routes use the Universal engine
app.get('*', (req, res) => {
res.render('index', { req });
});
server = http.createServer(app);
server.listen(port);
server.on("error", onError);
server.on("listening", onListening);
Notes:
The build works when launched trough node straight, with prerendering and all.
When trying to launch the IIS server we get the following error (after disabling dev errors in web.config):
I'll be so happy if this will work, since we're trying to find the perfect solution for SEO prerendering using Universal & Express on IIS.
Many thanks in advance.
The text was updated successfully, but these errors were encountered:
Same issue and no combination of web.config files I've found anywhere seem to solve the issue. It's been a couple years @TomasKatz did you find a solution?
We are trying to set up an IISNODE server with pre-rendering using Universal.
I set up the project the following way with web.config and main server script as follows:
web.config:
Main script (server.ts):
Notes:
I'll be so happy if this will work, since we're trying to find the perfect solution for SEO prerendering using Universal & Express on IIS.
Many thanks in advance.
The text was updated successfully, but these errors were encountered: