Angular Server Side Rendering issue with ORIGIN_URL #709

Closed
opened 2025-08-09 17:17:22 +00:00 by fergalmoran · 0 comments
Owner

Originally created by @AmrineA on 5/30/2017

I noticed in the out of the box templates, I'm able to go to the Fetch Data page and refresh the browser and it properly does the call out to the server as you would expect. However, in my application, I get a completely different result.

Exception: Call to Node module failed with error: Error: URLs requested via Http on the server must be absolute. URL: undefined/api/Cases/1

I'm importing ORIGIN_URL into the method that needs the value, but it is coming back as undefined for some reason. I've also got it in the boot-server.ts file:

import 'reflect-metadata';
import 'zone.js';
import 'rxjs/add/operator/first';
import { enableProdMode, ApplicationRef, NgZone, ValueProvider } from '@angular/core';
import { platformDynamicServer, PlatformState, INITIAL_CONFIG } from '@angular/platform-server';
import { createServerRenderer, RenderResult } from 'aspnet-prerendering';
import { AppModule } from './app/app.module.server';

enableProdMode();

export default createServerRenderer(params => {
    const providers = [
        { provide: INITIAL_CONFIG, useValue: { document: '<app></app>', url: params.url } },
        { provide: 'ORIGIN_URL', useValue: params.origin }
    ];

    return platformDynamicServer(providers).bootstrapModule(AppModule).then(moduleRef => {
        const appRef = moduleRef.injector.get(ApplicationRef);
        const state = moduleRef.injector.get(PlatformState);
        const zone = moduleRef.injector.get(NgZone);

        return new Promise<RenderResult>((resolve, reject) => {
            zone.onError.subscribe(errorInfo => reject(errorInfo));
            appRef.isStable.first(isStable => isStable).subscribe(() => {
                // Because 'onStable' fires before 'onError', we have to delay slightly before
                // completing the request in case there's an error to report
                setImmediate(() => {
                    resolve({
                        html: state.renderToString()
                    });
                    moduleRef.destroy();
                });
            });
        });
    });
});

Where does params.origin get its value from? Does that need set somewhere that I'm missing?

*Originally created by @AmrineA on 5/30/2017* I noticed in the out of the box templates, I'm able to go to the Fetch Data page and refresh the browser and it properly does the call out to the server as you would expect. However, in my application, I get a completely different result. `Exception: Call to Node module failed with error: Error: URLs requested via Http on the server must be absolute. URL: undefined/api/Cases/1` I'm importing ORIGIN_URL into the method that needs the value, but it is coming back as undefined for some reason. I've also got it in the boot-server.ts file: ``` import 'reflect-metadata'; import 'zone.js'; import 'rxjs/add/operator/first'; import { enableProdMode, ApplicationRef, NgZone, ValueProvider } from '@angular/core'; import { platformDynamicServer, PlatformState, INITIAL_CONFIG } from '@angular/platform-server'; import { createServerRenderer, RenderResult } from 'aspnet-prerendering'; import { AppModule } from './app/app.module.server'; enableProdMode(); export default createServerRenderer(params => { const providers = [ { provide: INITIAL_CONFIG, useValue: { document: '<app></app>', url: params.url } }, { provide: 'ORIGIN_URL', useValue: params.origin } ]; return platformDynamicServer(providers).bootstrapModule(AppModule).then(moduleRef => { const appRef = moduleRef.injector.get(ApplicationRef); const state = moduleRef.injector.get(PlatformState); const zone = moduleRef.injector.get(NgZone); return new Promise<RenderResult>((resolve, reject) => { zone.onError.subscribe(errorInfo => reject(errorInfo)); appRef.isStable.first(isStable => isStable).subscribe(() => { // Because 'onStable' fires before 'onError', we have to delay slightly before // completing the request in case there's an error to report setImmediate(() => { resolve({ html: state.renderToString() }); moduleRef.destroy(); }); }); }); }); }); ``` Where does params.origin get its value from? Does that need set somewhere that I'm missing?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/JavaScriptServices#709
No description provided.