mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-23 01:58:29 +00:00
Update to latest Angular2/angular-universal and use relative URLs in template's HTTP request
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "aspnet-prerendering",
|
||||
"version": "1.0.0",
|
||||
"version": "1.0.1",
|
||||
"description": "Helpers for server-side rendering of JavaScript applications in ASP.NET projects. Works in conjunction with the Microsoft.AspNet.SpaServices NuGet package.",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
||||
@@ -19,9 +19,10 @@ export interface BootFunc {
|
||||
}
|
||||
|
||||
export interface BootFuncParams {
|
||||
location: url.Url;
|
||||
url: string;
|
||||
absoluteUrl: string;
|
||||
location: url.Url; // e.g., Location object containing information '/some/path'
|
||||
origin: string; // e.g., 'https://example.com:1234'
|
||||
url: string; // e.g., '/some/path'
|
||||
absoluteUrl: string; // e.g., 'https://example.com:1234/some/path'
|
||||
domainTasks: Promise<any>;
|
||||
}
|
||||
|
||||
@@ -44,8 +45,10 @@ export function renderToString(callback: RenderToStringCallback, applicationBase
|
||||
const domainTaskCompletionPromise = new Promise((resolve, reject) => {
|
||||
domainTaskCompletionPromiseResolve = resolve;
|
||||
});
|
||||
const parsedAbsoluteRequestUrl = url.parse(absoluteRequestUrl);
|
||||
const params: BootFuncParams = {
|
||||
location: url.parse(requestPathAndQuery),
|
||||
origin: parsedAbsoluteRequestUrl.protocol + '//' + parsedAbsoluteRequestUrl.host,
|
||||
url: requestPathAndQuery,
|
||||
absoluteUrl: absoluteRequestUrl,
|
||||
domainTasks: domainTaskCompletionPromise
|
||||
|
||||
@@ -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