mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-22 17:47:53 +00:00
Update to latest Angular2/angular-universal and use relative URLs in template's HTTP request
This commit is contained in:
@@ -2,17 +2,18 @@ import 'angular2-universal/polyfills';
|
||||
import * as ngCore from 'angular2/core';
|
||||
import * as ngRouter from 'angular2/router';
|
||||
import * as ngUniversal from 'angular2-universal';
|
||||
import { BASE_URL, ORIGIN_URL, REQUEST_URL } from 'angular2-universal/common';
|
||||
import { App } from './components/app/app';
|
||||
|
||||
export default function (params: any): Promise<{ html: string, globals?: any }> {
|
||||
const serverBindings = [
|
||||
ngCore.provide(ngUniversal.BASE_URL, { useValue: params.absoluteUrl }),
|
||||
ngCore.provide(ngUniversal.REQUEST_URL, { useValue: params.url }),
|
||||
ngCore.provide(ngRouter.APP_BASE_HREF, { useValue: '/' }),
|
||||
ngCore.provide(BASE_URL, { useValue: '/' }),
|
||||
ngCore.provide(ORIGIN_URL, { useValue: params.origin }),
|
||||
ngCore.provide(REQUEST_URL, { useValue: params.url }),
|
||||
ngUniversal.NODE_HTTP_PROVIDERS,
|
||||
ngUniversal.NODE_ROUTER_PROVIDERS
|
||||
];
|
||||
|
||||
|
||||
return ngUniversal.bootloader({
|
||||
directives: [App],
|
||||
providers: serverBindings,
|
||||
|
||||
@@ -12,10 +12,8 @@ export class FetchData {
|
||||
// Workaround for RC1 bug. This can be removed with ASP.NET Core 1.0 RC2.
|
||||
let isServerSide = typeof window === 'undefined';
|
||||
let options: any = isServerSide ? { headers: { Connection: 'keep-alive' } } : null;
|
||||
|
||||
// TODO: Switch to relative URL once angular-universal supports them
|
||||
// https://github.com/angular/universal/issues/348
|
||||
http.get('http://localhost:5000/api/SampleData/WeatherForecasts', options).subscribe(result => {
|
||||
|
||||
http.get('/api/SampleData/WeatherForecasts', options).subscribe(result => {
|
||||
this.forecasts = result.json();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -18,9 +18,9 @@
|
||||
"webpack-hot-middleware": "^2.10.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"angular2": "2.0.0-beta.13",
|
||||
"angular2-universal": "0.90.1",
|
||||
"aspnet-prerendering": "^1.0.0",
|
||||
"angular2": "2.0.0-beta.15",
|
||||
"angular2-universal": "0.98.1",
|
||||
"aspnet-prerendering": "^1.0.1",
|
||||
"aspnet-webpack": "^1.0.1",
|
||||
"css": "^2.2.1",
|
||||
"isomorphic-fetch": "^2.2.1",
|
||||
|
||||
Reference in New Issue
Block a user