- User Data ({{ userId$ | async }})
-
- {{user$ | async | json}}
-
+
+
+ User Data
+
+
+
+ {{ user.id }}
+
+ {{ user.name }}
+
+ {{ user.email }}
+
+ {{ user.company.name }}
+
+
+ {{ user.company.catchPhrase }}
+
+
+
Previous ({{ prev$ | async }})
Next ({{ next$ | async }})
+
+
+
diff --git a/projects/sampleBlog/src/app/user/user.component.ts b/projects/sampleBlog/src/app/user/user.component.ts
index eccb9f078..15e8aec84 100644
--- a/projects/sampleBlog/src/app/user/user.component.ts
+++ b/projects/sampleBlog/src/app/user/user.component.ts
@@ -36,7 +36,7 @@ export class UserComponent implements OnInit {
// This is an example of using TransferState
user$ = isScullyGenerated()
- ? this.transferState.getState('user')
+ ? this.transferState.getState('user')
: this.apiUser$.pipe(tap(user => this.transferState.setState('user', user)));
constructor(
diff --git a/projects/sampleBlog/src/app/user/user.module.ts b/projects/sampleBlog/src/app/user/user.module.ts
index 0a367f058..92084bb1c 100644
--- a/projects/sampleBlog/src/app/user/user.module.ts
+++ b/projects/sampleBlog/src/app/user/user.module.ts
@@ -1,11 +1,13 @@
-import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
-
+import {NgModule} from '@angular/core';
+import {PostComponent} from './post/post.component';
+import {PostsComponent} from './posts/posts.component';
import {UserRoutingModule} from './user-routing.module';
import {UserComponent} from './user.component';
+import {UsersComponent} from './users/users.component';
@NgModule({
- declarations: [UserComponent],
+ declarations: [UserComponent, UsersComponent, PostsComponent, PostComponent],
imports: [CommonModule, UserRoutingModule],
})
export class UserModule {}
diff --git a/projects/sampleBlog/src/app/user/users/users.component.css b/projects/sampleBlog/src/app/user/users/users.component.css
new file mode 100644
index 000000000..e69de29bb
diff --git a/projects/sampleBlog/src/app/user/users/users.component.html b/projects/sampleBlog/src/app/user/users/users.component.html
new file mode 100644
index 000000000..4eb2e3c0c
--- /dev/null
+++ b/projects/sampleBlog/src/app/user/users/users.component.html
@@ -0,0 +1,18 @@
+Users
+
+
diff --git a/projects/sampleBlog/src/app/user/users/users.component.spec.ts b/projects/sampleBlog/src/app/user/users/users.component.spec.ts
new file mode 100644
index 000000000..554295d92
--- /dev/null
+++ b/projects/sampleBlog/src/app/user/users/users.component.spec.ts
@@ -0,0 +1,24 @@
+import {async, ComponentFixture, TestBed} from '@angular/core/testing';
+
+import {UsersComponent} from './users.component';
+
+describe('UsersComponent', () => {
+ let component: UsersComponent;
+ let fixture: ComponentFixture;
+
+ beforeEach(async(() => {
+ TestBed.configureTestingModule({
+ declarations: [UsersComponent],
+ }).compileComponents();
+ }));
+
+ beforeEach(() => {
+ fixture = TestBed.createComponent(UsersComponent);
+ component = fixture.componentInstance;
+ fixture.detectChanges();
+ });
+
+ it('should create', () => {
+ expect(component).toBeTruthy();
+ });
+});
diff --git a/projects/sampleBlog/src/app/user/users/users.component.ts b/projects/sampleBlog/src/app/user/users/users.component.ts
new file mode 100644
index 000000000..827b43776
--- /dev/null
+++ b/projects/sampleBlog/src/app/user/users/users.component.ts
@@ -0,0 +1,27 @@
+import {HttpClient} from '@angular/common/http';
+import {Component, OnInit} from '@angular/core';
+import {isScullyGenerated, TransferStateService} from '@scullyio/ng-lib';
+import {of} from 'rxjs';
+import {catchError, shareReplay, tap} from 'rxjs/operators';
+import {User} from '../user.component';
+
+@Component({
+ selector: 'app-users',
+ templateUrl: './users.component.html',
+ styleUrls: ['./users.component.css'],
+})
+export class UsersComponent implements OnInit {
+ apiUsers$ = this.http.get(`https://jsonplaceholder.typicode.com/users`).pipe(
+ catchError(() => of([] as User[])),
+ shareReplay(1)
+ );
+
+ // This is an example of using TransferState
+ users$ = isScullyGenerated()
+ ? this.transferState.getState('users')
+ : this.apiUsers$.pipe(tap(user => this.transferState.setState('users', user)));
+
+ constructor(private http: HttpClient, private transferState: TransferStateService) {}
+
+ ngOnInit() {}
+}
diff --git a/scully.config.js b/scully.config.js
index a845b84db..755aaa6f9 100644
--- a/scully.config.js
+++ b/scully.config.js
@@ -9,7 +9,7 @@ exports.config = {
/** outDir is where the static distribution files end up */
outDir: './dist/static',
// hostName: '0.0.0.0',
- extraRoutes: [''],
+ extraRoutes: ['', '/user/:userId/post/:post'],
projectName: 'sampleBlog',
routes: {
'/demo/:id': {
@@ -35,6 +35,21 @@ exports.config = {
property: 'id',
},
},
+ '/user/:userId/post/:post': {
+ // Type is mandatory
+ type: 'json',
+ /**
+ * Every parameter in the route must exist here
+ */
+ userId: {
+ url: 'https://jsonplaceholder.typicode.com/users',
+ property: 'id',
+ },
+ post: {
+ url: 'https://jsonplaceholder.typicode.com/posts?userId=${userId}',
+ property: 'id',
+ },
+ },
'/nouser/:userId/:friendCode': {
// Type is mandatory
type: 'json',
diff --git a/scully/routerPlugins/jsonRoutePlugin.ts b/scully/routerPlugins/jsonRoutePlugin.ts
index 2320bba5f..34547a377 100644
--- a/scully/routerPlugins/jsonRoutePlugin.ts
+++ b/scully/routerPlugins/jsonRoutePlugin.ts
@@ -22,7 +22,7 @@ export const jsonRoutePlugin = async (route: string, conf: RouteTypeJson): Promi
/** helper to get the data, parses out the context, and the property */
const loadData = (param, context = {}): Promise => {
/** us es-template lie string to construct the url */
- const url = renderTemplate(conf[param.part].url, context);
+ const url = renderTemplate(conf[param.part].url, context).trim();
return httpGetJson(url, {
headers: conf[param.part].headers,
})
diff --git a/scully/utils/defaultAction.ts b/scully/utils/defaultAction.ts
index 4d39e5896..2af7005df 100644
--- a/scully/utils/defaultAction.ts
+++ b/scully/utils/defaultAction.ts
@@ -27,7 +27,7 @@ export const generateAll = async (config?: Partial) => {
log('Pull in data to create additional routes.');
const handledRoutes = await addOptionalRoutes(unhandledRoutes);
- await storeRoutes(handledRoutes);
+ // await storeRoutes(handledRoutes);
/** launch the browser, its shared among renderers */
const browser = await launchedBrowser();
/** start handling each route, works in chunked parallel mode */
diff --git a/scully/utils/httpGetJson.ts b/scully/utils/httpGetJson.ts
index 92322788f..53464bf77 100644
--- a/scully/utils/httpGetJson.ts
+++ b/scully/utils/httpGetJson.ts
@@ -11,12 +11,12 @@ export function httpGetJson(
) {
const httpGet = url.toLowerCase().includes('https:') ? getHttps : get;
return new Promise((resolve, reject) => {
- const {pathname, hostname, port, protocol} = new URL(url);
+ const {pathname, hostname, port, protocol, search, hash} = new URL(url);
const opt: RequestOptions = {
protocol,
hostname,
port,
- path: pathname,
+ path: pathname + search + hash,
headers,
};
httpGet(opt, res => {