mirror of
https://github.com/OpenLiberty/liberty-bikes.git
synced 2025-01-24 10:34:03 +08:00
Move service URLs to environment variables
This commit is contained in:
parent
ece29d1f09
commit
abd22c835c
@ -5,6 +5,8 @@ import { LoginComponent } from './login/login.component';
|
||||
import { GameComponent } from './game/game.component';
|
||||
import { ControlsComponent } from './controls/controls.component';
|
||||
|
||||
import { environment } from './../environments/environment';
|
||||
|
||||
const routes: Routes = [
|
||||
{ path: 'login', component: LoginComponent },
|
||||
{ path: 'game', component: GameComponent },
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { SocketService } from '../net/socket.service';
|
||||
import { Subject } from 'rxjs/Subject';
|
||||
import { environment } from './../../environments/environment';
|
||||
import 'rxjs/add/operator/map';
|
||||
|
||||
|
||||
@ -10,16 +11,12 @@ export class GameService {
|
||||
public messages: Subject<Object>;
|
||||
|
||||
roundId: string;
|
||||
serverHost: string;
|
||||
serverPort: string;
|
||||
|
||||
constructor(socketService: SocketService) {
|
||||
this.roundId = sessionStorage.getItem('roundId');
|
||||
console.log(`Round ID: ${this.roundId}`);
|
||||
this.serverHost = document.location.hostname;
|
||||
this.serverPort = '8080';
|
||||
|
||||
socketService.url = `ws://${this.serverHost}:${this.serverPort}/round/ws/${this.roundId}`;
|
||||
socketService.url = `${environment.API_URL_GAME_WS}/${this.roundId}`;
|
||||
this.messages = <Subject<Object>>socketService.socket
|
||||
.map((response: MessageEvent): any => {
|
||||
console.log(`Game service handling message: ${response.data}`);
|
||||
|
@ -2,6 +2,7 @@ import { Component, OnInit, NgZone } from '@angular/core';
|
||||
import { Meta } from '@angular/platform-browser';
|
||||
import { Router } from '@angular/router';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { environment } from './../../environments/environment';
|
||||
|
||||
import * as $ from 'jquery';
|
||||
|
||||
@ -22,13 +23,13 @@ export class LoginComponent implements OnInit {
|
||||
this.meta.removeTag('viewport');
|
||||
let viewWidth = $(window).width();
|
||||
let viewHeight = $(window).height();
|
||||
|
||||
|
||||
this.meta.addTag({name: 'viewport', content: `width=${viewWidth}px, height=${viewHeight}px, initial-scale=1.0`}, true);
|
||||
}
|
||||
|
||||
async createRound() {
|
||||
try {
|
||||
let data = await this.http.post(`http://${document.location.hostname}:8080/round/create`, "", { responseType: 'text'}).toPromise();
|
||||
let data = await this.http.post(`${environment.API_URL_GAME_ROUND}/create`, "", { responseType: 'text'}).toPromise();
|
||||
alert(`Created round: ${data}`);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
@ -55,7 +56,7 @@ async joinRound(gameBoard: boolean) {
|
||||
}
|
||||
|
||||
try {
|
||||
let data: any = await this.http.get(`http://${document.location.hostname}:8080/round/${roundID}`).toPromise();
|
||||
let data: any = await this.http.get(`${environment.API_URL_GAME_ROUND}/${roundID}`).toPromise();
|
||||
console.log(JSON.stringify(data));
|
||||
if (data === null) {
|
||||
alert('Game round does not exist!');
|
||||
@ -74,7 +75,7 @@ async joinRound(gameBoard: boolean) {
|
||||
return;
|
||||
}
|
||||
|
||||
let response: any = await this.http.post(`http://${document.location.hostname}:8081/player/create?name=${username}`, "", {
|
||||
let response: any = await this.http.post(`${environment.API_URL_PLAYERS}/create?name=${username}`, "", {
|
||||
responseType: 'text'
|
||||
}).toPromise();
|
||||
console.log(JSON.stringify(response));
|
||||
@ -108,7 +109,7 @@ async joinRound(gameBoard: boolean) {
|
||||
let router = this.router;
|
||||
|
||||
try {
|
||||
let data = await this.http.post(`http://${document.location.hostname}:8080/round/create`, "", { responseType: 'text' }).toPromise();
|
||||
let data = await this.http.post(`${environment.API_URL_GAME_ROUND}/create`, "", { responseType: 'text' }).toPromise();
|
||||
console.log(`Created round with id=${data}`);
|
||||
sessionStorage.setItem('isSpectator', 'true');
|
||||
sessionStorage.setItem('roundId', data);
|
||||
|
@ -4,5 +4,10 @@
|
||||
// The list of which env maps to which file can be found in `.angular-cli.json`.
|
||||
|
||||
export const environment = {
|
||||
production: false
|
||||
production: false,
|
||||
API_URL_AUTH: 'http://localhost:8082',
|
||||
API_URL_GAME_ROUND: 'http://localhost:8080/round',
|
||||
API_URL_GAME_WS: 'ws://localhost:8080/round/ws',
|
||||
API_URL_PLAYERS: 'http://localhost:8081/player',
|
||||
API_URL_RANKS: 'http://localhost:8081/rank'
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user