Skip to content

Commit

Permalink
Merge pull request #871 from atmire/fix-express-error-handler
Browse files Browse the repository at this point in the history
Ensure CSR fallback only happens on actual errors
  • Loading branch information
tdonohue committed Sep 22, 2020
2 parents 9f396f7 + 5afd4a6 commit 6960597
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions server.ts
Expand Up @@ -33,7 +33,7 @@ import { enableProdMode, NgModuleFactory, Type } from '@angular/core';
import { REQUEST, RESPONSE } from '@nguniversal/express-engine/tokens';
import { environment } from './src/environments/environment';
import { createProxyMiddleware } from 'http-proxy-middleware';
import { hasValue } from './src/app/shared/empty.util';
import { hasValue, hasNoValue } from './src/app/shared/empty.util';

/*
* Set path for the browser application's dist folder
Expand Down Expand Up @@ -140,12 +140,16 @@ function ngApp(req, res) {
baseUrl: environment.ui.nameSpace,
originUrl: environment.ui.baseUrl,
requestUrl: req.originalUrl
}, (err) => {
console.warn('Error in SSR, serving for direct CSR.');
if (hasValue(err)) {
console.warn('Error details : ', err);
}, (err, data) => {
if (hasNoValue(err) && hasValue(data)) {
res.send(data);
} else {
console.warn('Error in SSR, serving for direct CSR.');
if (hasValue(err)) {
console.warn('Error details : ', err);
}
res.sendFile(DIST_FOLDER + '/index.html');
}
res.sendFile(DIST_FOLDER + '/index.html');
})
} else {
// If preboot is disabled, just serve the client
Expand Down

0 comments on commit 6960597

Please sign in to comment.