Added proxy to bb frontend (no need for cross-origin headers); support periodic status calls
parent
c0b21f82ee
commit
173b952e09
|
@ -4,7 +4,7 @@
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"ng": "ng",
|
"ng": "ng",
|
||||||
"start": "ng serve",
|
"start": "ng serve --proxy-config proxy.conf.json",
|
||||||
"build": "ng build",
|
"build": "ng build",
|
||||||
"test": "ng test",
|
"test": "ng test",
|
||||||
"lint": "ng lint",
|
"lint": "ng lint",
|
||||||
|
@ -23,7 +23,7 @@
|
||||||
"@angular/router": "^4.0.0",
|
"@angular/router": "^4.0.0",
|
||||||
"@types/long": "^3.0.31",
|
"@types/long": "^3.0.31",
|
||||||
"core-js": "^2.4.1",
|
"core-js": "^2.4.1",
|
||||||
"protobuf.js": "^6.8.0",
|
"protobufjs": "^6.8.0",
|
||||||
"rxjs": "^5.1.0",
|
"rxjs": "^5.1.0",
|
||||||
"zone.js": "^0.8.4"
|
"zone.js": "^0.8.4"
|
||||||
},
|
},
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"/bbserver" : {
|
||||||
|
"target" : "http://localhost:8081/",
|
||||||
|
"secure" : false
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
import {Component, OnInit} from '@angular/core';
|
import {Component, OnInit} from '@angular/core';
|
||||||
import {BBService} from "./bb.service"; // respectively "./node_modules/protobufjs"
|
import {IntervalObservable} from "rxjs/observable/IntervalObservable";
|
||||||
|
import {BBService} from "./bb.service";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-root',
|
selector: 'app-root',
|
||||||
|
@ -15,14 +15,39 @@ export class AppComponent implements OnInit {
|
||||||
status = 'Not connected';
|
status = 'Not connected';
|
||||||
errorMessage = '';
|
errorMessage = '';
|
||||||
|
|
||||||
|
private alive: boolean; // used to unsubscribe from the IntervalObservable
|
||||||
|
// when OnDestroy is called.
|
||||||
|
|
||||||
constructor(private bbservice : BBService) { }
|
constructor(private bbservice : BBService) { }
|
||||||
|
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
|
|
||||||
|
// Get initial status
|
||||||
this.bbservice.getStatus().subscribe(
|
this.bbservice.getStatus().subscribe(
|
||||||
status => this.status = status.name,
|
status => { this.status = status.name },
|
||||||
error => this.errorMessage = <any>error
|
error => this.errorMessage = <any>error
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.alive = true;
|
||||||
|
// Get new status every second
|
||||||
|
let o = IntervalObservable.create(1000)
|
||||||
|
//.takeWhile(() => this.alive) // only fires when component is alive
|
||||||
|
.subscribe(n => {
|
||||||
|
if (!this.alive) {
|
||||||
|
o.unsubscribe();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.bbservice.getStatus().subscribe(
|
||||||
|
status => this.status = status.name + " " + n,
|
||||||
|
error => this.errorMessage = <any>error
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ngOnDestroy(){
|
||||||
|
this.alive = false; // switches your IntervalObservable off
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import 'rxjs/add/operator/map';
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class BBService {
|
export class BBService {
|
||||||
private headers = new Headers({'Content-Type': 'application/x-protobuf'});
|
private headers = new Headers({'Content-Type': 'application/x-protobuf'});
|
||||||
private bbUrl = 'http://localhost:8081/bbserver'; // URL to web api
|
private bbUrl = '/bbserver'; // URL to web api
|
||||||
private statusPath = '/status';
|
private statusPath = '/status';
|
||||||
|
|
||||||
constructor(private http: Http) { }
|
constructor(private http: Http) { }
|
||||||
|
|
|
@ -56,15 +56,15 @@ public class BulletinBoardWebApp implements BulletinBoardServer, ServletContextL
|
||||||
String dbType = servletContext.getInitParameter("dbType");
|
String dbType = servletContext.getInitParameter("dbType");
|
||||||
String dbName = servletContext.getInitParameter("dbName");
|
String dbName = servletContext.getInitParameter("dbName");
|
||||||
|
|
||||||
if ("SQLite".equals(dbType)){
|
if ("SQLite".equalsIgnoreCase(dbType)){
|
||||||
|
|
||||||
bulletinBoard = new BulletinBoardSQLServer(new SQLiteQueryProvider(dbName));
|
bulletinBoard = new BulletinBoardSQLServer(new SQLiteQueryProvider(dbName));
|
||||||
|
|
||||||
} else if ("H2".equals(dbType)) {
|
} else if ("H2".equalsIgnoreCase(dbType)) {
|
||||||
|
|
||||||
bulletinBoard = new BulletinBoardSQLServer(new H2QueryProvider(dbName));
|
bulletinBoard = new BulletinBoardSQLServer(new H2QueryProvider(dbName));
|
||||||
|
|
||||||
} else if ("MySQL".equals(dbType)) {
|
} else if ("MySQL".equalsIgnoreCase(dbType)) {
|
||||||
|
|
||||||
String dbAddress = servletContext.getInitParameter("dbAddress");
|
String dbAddress = servletContext.getInitParameter("dbAddress");
|
||||||
int dbPort = Integer.parseInt(servletContext.getInitParameter("dbPort"));
|
int dbPort = Integer.parseInt(servletContext.getInitParameter("dbPort"));
|
||||||
|
@ -93,7 +93,7 @@ public class BulletinBoardWebApp implements BulletinBoardServer, ServletContextL
|
||||||
@Consumes(MEDIATYPE_PROTOBUF)
|
@Consumes(MEDIATYPE_PROTOBUF)
|
||||||
@Produces(MEDIATYPE_PROTOBUF)
|
@Produces(MEDIATYPE_PROTOBUF)
|
||||||
public ServerStatus getStatus(@Context HttpServletResponse response) throws CommunicationException {
|
public ServerStatus getStatus(@Context HttpServletResponse response) throws CommunicationException {
|
||||||
response.setHeader("Access-Control-Allow-Origin", "*"); // TODO: Remove
|
// response.setHeader("Access-Control-Allow-Origin", "*"); // TODO: Remove
|
||||||
return ServerStatus.newBuilder()
|
return ServerStatus.newBuilder()
|
||||||
.setName("Hello")
|
.setName("Hello")
|
||||||
.build();
|
.build();
|
||||||
|
|
Loading…
Reference in New Issue