Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The Node.JS application failed to respond within the given startup time #73

Open
DmitriyKarpovBrimit opened this issue Mar 20, 2024 · 2 comments

Comments

@DmitriyKarpovBrimit
Copy link

DmitriyKarpovBrimit commented Mar 20, 2024

Hi everyone!

I encountered an error while deploying the project:

fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
An unhandled exception has occurred while executing the request.
System.ApplicationException: The Node.JS application failed to respond within the given startup time
at HeadlessCms.Infrastructure.NodeJsMiddleware.NodeJsProcess.WhenReady(CancellationToken cancellationToken) in D:\Projects\Optimizely\FoundationSpaReact\Foundation-spa-react\src\Headless.Cms\Infrastructure\NodeJsMiddleware\NodeJsProcess.cs:line 92
at HeadlessCms.Infrastructure.NodeJsMiddleware.NodeJsMiddleware.InvokeAsync(HttpContext context) in D:\Projects\Optimizely\FoundationSpaReact\Foundation-spa-react\src\Headless.Cms\Infrastructure\NodeJsMiddleware\NodeJsMiddleware.cs:line 56
at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
at SixLabors.ImageSharp.Web.Middleware.ImageSharpMiddleware.Invoke(HttpContext httpContext, Boolean retry)
at Microsoft.AspNetCore.ResponseCompression.ResponseCompressionMiddleware.InvokeCore(HttpContext context)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

I get this error when I run the Headless.Cms project (back-end part).
I followed the instructions for deploying the backend and frontend as described in the Readme file.

Backend part:
On the backend side, I successfully executed the commands from point 1.2. Installation. I changed the data in the appsettings.json file in accordance with paragraph 1.3. Service configuration. After that, I decided to launch the site, and, as written in the documentation, the content began to load (I understood this because additional tables began to be created in the database and content was loaded into them). After the content download was completed, I launched the site at this address https://localhost:8001/ - I successfully logged in and checked that there were many content pages in the content tree. I also checked that my user has the 2 required roles WEBADMINS and ADMINISTRATORS in accordance with paragraph 2.1. Configure user accounts. And the last step in setting up the backend was changing the NodeJsMiddleware section in the appsettings.json file, namely, I set port 3000 to listen to the frontend and “Disabled”: “false” to run a JavaScript based frontend as child process of the .Net webserver, as well as several other options in this section.

Frontend part:
Everything is much simpler here - I successfully completed the entire sequence of commands, including changing the site ID in the "OPTIMIZELY_DXP_SITE_ID" parameter.

And this is what I have as a result:

Backend - home page doesn't load (in the backend console i've the same issue):
image

Frontend console:
image

Frontend website with 404 error:
image

EPiServer works correctly and we see the content, but due to the same error we cannot view it:
image

We see that the frontend is trying to get some data from this URL https://localhost:8001/ but due to a backend error it cannot be done and the frontend side (http://localhost:3000/) does not load the site content.

Also I have a question, is setting up OpenID Connect a requirement? In particular, I am interested in the relevance of setting point 3.2. Applications.

I will be very glad to receive some advice to help launch this headless solution, it seems like some final piece is missing. Thanks for any help.
@remkoj

@karolberezicki
Copy link

I have the same issue - I was able to to run the front-end part with the command that back-end is trying to execute

C:\path\to\node.exe --require=C:\repos\Foundation-spa-react\src\frontend\.pnp.cjs --loader=file:///C:\repos\Foundation-spa-react\src\frontend\.pnp.loader.mjs C:\repos\Foundation-spa-react\src\frontend\dotnet.js 3000

and it runs successfully, however returns 404, that's why the back-end reports ApplicationException("The Node.JS application failed to respond within the given startup time").

My best guess is that something have changed with Content Delivery API integration, but haven't been able to pin-point the exact issue.

@tago-SE
Copy link

tago-SE commented Sep 19, 2024

/Hopefully this helps resolve the issue

I ran the frontend locally on http://localhost:3000 which means that the CMS should be http://localhost:8000 (not 8001). The issue I encounter after that is that the site/{id}/routes return paths with https://localhost:8001/ and then the resolveRoute function uses the href which is using OPTIMIZELY_DXP_URL=http://localhost:8000/ causing it not to match.

So if you modify the ContentDeliveryAPI resolveRoute function from using href to pathname it will find the page. packages\optimizely\cms\src\content-delivery\content-delivery-api.ts

Not sure if this will break OPE or not as I haven't tested that yet...

public async resolveRoute<C extends IContent = IContent>(path : string, config: ContentRequest<C>) : Promise<C | undefined>
{
    const resolvablePath = new URL(path, this._frontendUrl);
    if (this._config.debug) {
        console.groupCollapsed("ContentDeliveryAPI: Resolve route")
        console.log("Route", resolvablePath.href) 
    }
    const req : RequestConfig<C> = { ...config, urlParams: { ...config.urlParams, 
    ContentUrl: resolvablePath.href //  <-- Changed from href to pathname may break OPE
    resolvablePath.pathname, MatchExact: 'true' } }
    const list = await this.doRequest<C[]>(OptiEndpoints.Content, req as RequestConfig<IContentIfOther<C>>)

    if (this._config.debug) {
        console.log(`Received ${ list?.length ?? 0 } content items for ${ path }`)
        console.groupEnd()
    }
    if (list && list.length === 1) return list[0]
    return undefined
}

Another solution would also be if your frontend ran by default using https maybe.

Update:

I ran the frontend after starting the backend using the suggestion from @karolberezicki in frontend/package.json you have the script which you can run: "dotnet": "node --require=./.pnp.cjs --loader=./.pnp.loader.mjs dotnet.js 3000".

This is what I get when clicking preview so probably need to add additional configuration for it to work which I haven't yet gotten to...
/
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants