Skip to content

Commit 77e298a

Browse files
authored
feat(modules): pass in absolute URL as default for view rendering (#897)
* Add the absolute URL to view generation to allow for access through the document's native location object NOTE: This will act as a precursor to correct absolute path resolution for `HttpClient`
1 parent 0096015 commit 77e298a

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

modules/aspnetcore-engine/src/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export function ngAspnetCoreEngine(options: IEngineOptions): Promise<IEngineRend
128128
.then(factory => {
129129
return renderModuleFactory(factory, {
130130
document: options.document || options.appSelector,
131-
url: options.url || options.request.url,
131+
url: options.url || options.request.absoluteUrl,
132132
extraProviders: extraProviders
133133
});
134134
})

modules/express-engine/src/main.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export function ngExpressEngine(setupOptions: NgSetupOptions) {
7676

7777
setupOptions.providers = setupOptions.providers || [];
7878

79+
const req = options.req;
7980
const extraProviders = setupOptions.providers.concat(
8081
options.providers,
8182
getReqResProviders(options.req, options.res),
@@ -84,7 +85,7 @@ export function ngExpressEngine(setupOptions: NgSetupOptions) {
8485
provide: INITIAL_CONFIG,
8586
useValue: {
8687
document: options.document || getDocument(filePath),
87-
url: options.url || options.req.originalUrl
88+
url: options.url || req.protocol + '://' + (req.get('host') || '') + req.originalUrl
8889
}
8990
}
9091
]);

modules/hapi-engine/src/main.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ const factoryCacheMap = new Map<Type<{}>, NgModuleFactory<{}>>();
5252
*/
5353
export function ngHapiEngine(options: RenderOptions) {
5454

55+
const req = options.req;
5556
const compilerFactory: CompilerFactory = platformDynamicServer().injector.get(CompilerFactory);
5657
const compiler: Compiler = compilerFactory.createCompiler([
5758
{
@@ -61,11 +62,13 @@ export function ngHapiEngine(options: RenderOptions) {
6162
}
6263
]);
6364

64-
if (options.req.raw.req.url === undefined) {
65+
if (req.raw.req.url === undefined) {
6566
return Promise.reject(new Error('url is undefined'));
6667
}
6768

68-
const filePath = <string> options.req.raw.req.url;
69+
const rawUrl = req.url;
70+
const filePath = <string> req.raw.req.url;
71+
const url = `${rawUrl.protocol || ''}://${rawUrl.host || ''}${rawUrl.path || ''}`;
6972

7073
options.providers = options.providers || [];
7174

@@ -84,7 +87,7 @@ export function ngHapiEngine(options: RenderOptions) {
8487
provide: INITIAL_CONFIG,
8588
useValue: {
8689
document: options.document || getDocument(filePath),
87-
url: options.url || filePath
90+
url: options.url || url
8891
}
8992
}
9093
]);

0 commit comments

Comments
 (0)