Skip to content
This repository has been archived by the owner on Nov 22, 2024. It is now read-only.

Commit

Permalink
feat(modules): pass in absolute URL as default for view rendering (#897)
Browse files Browse the repository at this point in the history
* 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`
  • Loading branch information
CaerusKaru authored Dec 25, 2018
1 parent 0096015 commit 77e298a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion modules/aspnetcore-engine/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export function ngAspnetCoreEngine(options: IEngineOptions): Promise<IEngineRend
.then(factory => {
return renderModuleFactory(factory, {
document: options.document || options.appSelector,
url: options.url || options.request.url,
url: options.url || options.request.absoluteUrl,
extraProviders: extraProviders
});
})
Expand Down
3 changes: 2 additions & 1 deletion modules/express-engine/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export function ngExpressEngine(setupOptions: NgSetupOptions) {

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

const req = options.req;
const extraProviders = setupOptions.providers.concat(
options.providers,
getReqResProviders(options.req, options.res),
Expand All @@ -84,7 +85,7 @@ export function ngExpressEngine(setupOptions: NgSetupOptions) {
provide: INITIAL_CONFIG,
useValue: {
document: options.document || getDocument(filePath),
url: options.url || options.req.originalUrl
url: options.url || req.protocol + '://' + (req.get('host') || '') + req.originalUrl
}
}
]);
Expand Down
9 changes: 6 additions & 3 deletions modules/hapi-engine/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const factoryCacheMap = new Map<Type<{}>, NgModuleFactory<{}>>();
*/
export function ngHapiEngine(options: RenderOptions) {

const req = options.req;
const compilerFactory: CompilerFactory = platformDynamicServer().injector.get(CompilerFactory);
const compiler: Compiler = compilerFactory.createCompiler([
{
Expand All @@ -61,11 +62,13 @@ export function ngHapiEngine(options: RenderOptions) {
}
]);

if (options.req.raw.req.url === undefined) {
if (req.raw.req.url === undefined) {
return Promise.reject(new Error('url is undefined'));
}

const filePath = <string> options.req.raw.req.url;
const rawUrl = req.url;
const filePath = <string> req.raw.req.url;
const url = `${rawUrl.protocol || ''}://${rawUrl.host || ''}${rawUrl.path || ''}`;

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

Expand All @@ -84,7 +87,7 @@ export function ngHapiEngine(options: RenderOptions) {
provide: INITIAL_CONFIG,
useValue: {
document: options.document || getDocument(filePath),
url: options.url || filePath
url: options.url || url
}
}
]);
Expand Down

0 comments on commit 77e298a

Please sign in to comment.