Diagnosing problems on Angular4 server side rendering with Asp.net Core

We started our project with dotnet template for Angular with server side rendering (JavaScriptServices).
We sometimes get timeouts on the server side rendering of Angular4 and there isn't much on the exception to help us diagnose the problem, specially if all works well on the client side rendering.
Is there a way to access the console logs for the TS/JS code when running on the server side?
Or a way to get the call stack of the error? As we only get a message without any information of where it happens.

I tried to attach a debugger using these instructions but I get the error:

InvalidOperationException: The Node.js process failed to initialize: Warning: This is an experimental feature and could change at any time.


On the one hand here you have two good articles about the topic that probably you have already seen:

  • https://github.com/aspnet/JavaScriptServices/tree/dev/src/Microsoft.AspNetCore.SpaServices#debugging-your-javascripttypescript-code-when-it-runs-on-the-server

  • https://blogs.msdn.microsoft.com/webdev/2017/02/14/building-single-page-applications-on-asp-net-core-with-javascriptservices/

  • And on the other this question might bring you ideas on how to approach the problem, maybe you need to configure some Middleware in your start up class like Webpack or NodeServices:

  • https://github.com/aspnet/JavaScriptServices/issues/144
  • I hope this focus in the right direction.

    Juan


    From the link you posted is one way of handling diagnostics , We use JSNLog for our Applications .

    Install JSNLog in your Angular 2+ application

    On the command line, install the NPM package:

    npm install jsnlog --save
    

    Send uncaught JavaScript exceptions to the server

    An uncaught exception is simply an exception that isn't caught by your own code. You will want to log those to the server.

    By default, Angular handles uncaught exceptions by sending error messages to the console (details). To change this, you create a provider for the ErrorHandler interface (example).

  • Open your main module in your favorite editor. This is most often called app.module.ts.
  • Above the module definition, add an uncaught exception handler that uses JSNLog to log the JavaScript exception to the server:

     export class UncaughtExceptionHandler implements ErrorHandler {  handleError(error: any) {
           JL().fatalException('Uncaught Exception', error);
       } }
    
     // Existing module definition @NgModule({
       ...
    
  • The TypeScript compiler will complain, because you haven't imported JSNLog and ErrorHandler. Do that now:

    // ... other imports ...

    import { JL } from 'jsnlog';
    
    import { ErrorHandler } from '@angular/core';
    Finally add your uncaught exception handler to the providers list, as a provider for the ErrorHandler interface:
    @NgModule({
        ...
        providers: [
            ...
            { provide: ErrorHandler, useClass: UncaughtExceptionHandler }
        ],
        ...
    }) 
    
  • For more info refer this

    链接地址: http://www.djcxy.com/p/31384.html

    上一篇: 使用Node.js进行Angular4服务器端渲染

    下一篇: 使用Asp.net Core诊断Angular4服务器端渲染问题