|
5 | 5 | * Use of this source code is governed by an MIT-style license that can be |
6 | 6 | * found in the LICENSE file at https://angular.io/license |
7 | 7 | */ |
8 | | -import { Type, NgModuleFactory, CompilerFactory, Compiler } from '@angular/core'; |
| 8 | +import {Type, NgModuleFactory, CompilerFactory, Compiler, StaticProvider} from '@angular/core'; |
9 | 9 | import { platformDynamicServer } from '@angular/platform-server'; |
10 | 10 | import { DOCUMENT } from '@angular/common'; |
11 | 11 | import { ResourceLoader } from '@angular/compiler'; |
12 | 12 |
|
13 | | -import { REQUEST, ORIGIN_URL } from '../tokens'; |
| 13 | +import { REQUEST, ORIGIN_URL } from '@nguniversal/aspnetcore-engine/tokens'; |
14 | 14 | import { FileLoader } from './file-loader'; |
15 | 15 | import { IEngineOptions } from './interfaces/engine-options'; |
16 | 16 | import { IEngineRenderResult } from './interfaces/engine-render-result'; |
@@ -121,16 +121,8 @@ export function ngAspnetCoreEngine(options: IEngineOptions): Promise<IEngineRend |
121 | 121 |
|
122 | 122 | options.providers = options.providers || []; |
123 | 123 |
|
124 | | - const extraProviders = options.providers.concat( |
125 | | - [{ |
126 | | - provide: ORIGIN_URL, |
127 | | - useValue: options.request.origin |
128 | | - }, { |
129 | | - provide: REQUEST, |
130 | | - useValue: options.request.data.request |
131 | | - } |
132 | | - ] |
133 | | - ); |
| 124 | + const extraProviders = options.providers.concat(getReqResProviders(options.request.origin, |
| 125 | + options.request.data.request)); |
134 | 126 |
|
135 | 127 | getFactory(moduleOrFactory, compiler) |
136 | 128 | .then(factory => { |
@@ -167,6 +159,23 @@ export function ngAspnetCoreEngine(options: IEngineOptions): Promise<IEngineRend |
167 | 159 |
|
168 | 160 | } |
169 | 161 |
|
| 162 | +/** |
| 163 | + * Get providers of the request and response |
| 164 | + */ |
| 165 | +function getReqResProviders(origin: string, request: string): StaticProvider[] { |
| 166 | + const providers: StaticProvider[] = [ |
| 167 | + { |
| 168 | + provide: ORIGIN_URL, |
| 169 | + useValue: origin |
| 170 | + }, |
| 171 | + { |
| 172 | + provide: REQUEST, |
| 173 | + useValue: request |
| 174 | + } |
| 175 | + ]; |
| 176 | + return providers; |
| 177 | +} |
| 178 | + |
170 | 179 | /* @internal */ |
171 | 180 | const factoryCacheMap = new Map<Type<{}>, NgModuleFactory<{}>>(); |
172 | 181 | function getFactory( |
|
0 commit comments