Skip to content

Commit

Permalink
透過 proxy 呼叫遠端 API
Browse files Browse the repository at this point in the history
  • Loading branch information
Coffee0127 committed Apr 23, 2017
1 parent 37b4a93 commit bec178c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion front/package.json
Expand Up @@ -5,7 +5,7 @@
"angular-cli": {},
"scripts": {
"ng": "ng",
"start": "ng serve",
"start": "ng serve --proxy-config proxy.conf.json",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
Expand Down
7 changes: 7 additions & 0 deletions front/proxy.conf.json
@@ -0,0 +1,7 @@
{
"/api": {
"target": "http://localhost:8080/SampleProject",
"secure": false
}
}

7 changes: 4 additions & 3 deletions front/src/app/app.component.html
@@ -1,3 +1,4 @@
<h1>
{{title}}
</h1>
<pre>
{{ data | async | json }}
</pre>

12 changes: 11 additions & 1 deletion front/src/app/app.component.ts
@@ -1,10 +1,20 @@
import { Component } from '@angular/core';
import { Http, Response } from '@angular/http';

import 'rxjs/Rx';

@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'app works!';
data: any;

constructor(private http: Http) { }

ngOnInit() {
this.data = this.http.get('/api/cars/find')
.map((response: Response) => response.json());
}
}

0 comments on commit bec178c

Please sign in to comment.