diff --git a/package.json b/package.json index 42c95b5..b23a57a 100644 --- a/package.json +++ b/package.json @@ -34,12 +34,14 @@ "@ngrx/store": "^5.0.0", "@ngrx/store-devtools": "^5.0.1", "@swimlane/ngx-charts": "^7.1.1", + "@types/url-join": "^0.8.2", "core-js": "^2.5.3", "d3": "^4.13.0", "hammerjs": "^2.0.8", "ng2-odometer": "^1.1.3", "ngx-perfect-scrollbar": "^5.3.1", "rxjs": "^5.5.6", + "url-join": "^4.0.0", "zone.js": "^0.8.20" }, "devDependencies": { diff --git a/src/app/app-store.module.ts b/src/app/app-store.module.ts index 740e486..cb05799 100644 --- a/src/app/app-store.module.ts +++ b/src/app/app-store.module.ts @@ -12,7 +12,7 @@ import { combineReducers, ActionReducer, ActionReducerMap, MetaReducer } from '@ import { environment } from '../environments/environment'; -import { SimpleRouterStateSerializer } from './commons/router/state/serializer/simple-router-state-serializer'; +import { SimpleRouterStateSerializer } from 'packages/commons/util/router/state/serializer/simple-router-state-serializer'; export interface AppState { } diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 08afca6..222015d 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -12,8 +12,9 @@ import { CovalentModule } from './commons/ui/covalent/covalent.module'; import { AppComponent } from './app.component'; -import { RESTService } from './commons/service/rest.service'; -import { RPCService } from './commons/service/rpc.service'; +import { environment } from '../environments/environment'; +import { RESTService } from 'packages/commons/service/rest.service'; +import { RPCService } from 'packages/commons/service/rpc.service'; @NgModule({ declarations: [ @@ -29,6 +30,8 @@ import { RPCService } from './commons/service/rpc.service'; HttpClientModule, ], providers: [ + {provide: 'REST_BASE_URL', useValue: environment.restBaseURL}, + {provide: 'RPC_BASE_URL', useValue: environment.rpcBaseURL}, RESTService, RPCService, ], bootstrap: [AppComponent] diff --git a/src/environments/environment.prod.ts b/src/environments/environment.prod.ts index 3612073..721fa73 100644 --- a/src/environments/environment.prod.ts +++ b/src/environments/environment.prod.ts @@ -1,3 +1,6 @@ export const environment = { - production: true + production: true, + restBaseURL: 'http://127.0.0.1:19080', + rpcBaseURL: 'ws://127.0.0.1:19090/webapp', + }; diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 048a3c4..c5f1008 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -4,7 +4,9 @@ // The list of which env maps to which file can be found in `.angular-cli.json`. export const environment = { - production: false + production: false, + restBaseURL: 'http://127.0.0.1:19080', + rpcBaseURL: 'ws://127.0.0.1:19090/webapp', }; export const palete = { primary: '#D32F2F', diff --git a/src/packages/commons/commons.module.ts b/src/packages/commons/commons.module.ts deleted file mode 100644 index a61ff82..0000000 --- a/src/packages/commons/commons.module.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { NgModule } from '@angular/core'; -import { CommonModule } from '@angular/common'; - -@NgModule({ - imports: [ - CommonModule - ], - declarations: [] -}) -export class CommonsModule { } diff --git a/src/app/commons/service/rest.service.spec.ts b/src/packages/commons/service/rest.service.spec.ts similarity index 100% rename from src/app/commons/service/rest.service.spec.ts rename to src/packages/commons/service/rest.service.spec.ts diff --git a/src/app/commons/service/rest.service.ts b/src/packages/commons/service/rest.service.ts similarity index 64% rename from src/app/commons/service/rest.service.ts rename to src/packages/commons/service/rest.service.ts index e144c8b..97beb59 100644 --- a/src/app/commons/service/rest.service.ts +++ b/src/packages/commons/service/rest.service.ts @@ -1,20 +1,22 @@ import { Injectable, Inject } from '@angular/core'; -import { HttpClient, HttpHeaders } from '@angular/common/http'; +import { HttpClient, HttpHeaders, HttpErrorResponse } from '@angular/common/http'; import { Observable } from 'rxjs/Observable'; +import { Location } from '@angular/common'; + import 'rxjs/add/operator/do'; import 'rxjs/add/operator/timeout'; +import 'rxjs/add/observable/throw'; @Injectable() export class RESTService { - private baseURL: string; private readonly httpHeaders: HttpHeaders; constructor( + @Inject('REST_BASE_URL') private _baseURL: string, @Inject(HttpClient) private _httpClient: HttpClient, ) { - this.baseURL = 'http://192.168.1.103:19090/webapp'; this.httpHeaders = new HttpHeaders() .set('Accept', 'application/json') .set('Content-Type', 'application/json'); @@ -28,22 +30,26 @@ export class RESTService { const headers: HttpHeaders = this.httpHeaders; return this._httpClient - .get(`${this.baseURL}${entry}`, { + .get(Location.joinWithSlash(this._baseURL, entry), { headers: headers, params: params, responseType: 'json', - }); + }) + .map(response => response) + .catch((error: HttpErrorResponse) => Observable.throw(error.error)); } public post(entry: string, body: any | null, params?: {[param: string]: string | string[]}): Observable { const headers: HttpHeaders = this.httpHeaders; return this._httpClient - .post(`${this.baseURL}${entry}`, body, { + .post(Location.joinWithSlash(this._baseURL, entry), body, { headers: headers, params: params, responseType: 'json', - }); + }) + .map(response => response) + .catch((error: HttpErrorResponse) => Observable.throw(error.error)); } } diff --git a/src/app/commons/service/rpc.service.spec.ts b/src/packages/commons/service/rpc.service.spec.ts similarity index 100% rename from src/app/commons/service/rpc.service.spec.ts rename to src/packages/commons/service/rpc.service.spec.ts diff --git a/src/app/commons/service/rpc.service.ts b/src/packages/commons/service/rpc.service.ts similarity index 86% rename from src/app/commons/service/rpc.service.ts rename to src/packages/commons/service/rpc.service.ts index 1747200..a72c435 100644 --- a/src/app/commons/service/rpc.service.ts +++ b/src/packages/commons/service/rpc.service.ts @@ -1,4 +1,4 @@ -import { Injectable } from '@angular/core'; +import { Injectable, Inject } from '@angular/core'; import { Observable } from 'rxjs/Observable'; import { RxWebsocketSubject } from 'app/core/rx/websocket/rx-websocket-subject'; @@ -10,8 +10,10 @@ export class RPCService { private wsSocketSubject: RxWebsocketSubject; private rpcRegistry: RPCRegistry; - constructor() { - this.wsSocketSubject = new RxWebsocketSubject('ws://127.0.0.1:19090/webapp'); + constructor( + @Inject('RPC_BASE_URL') private _baseURL: string, + ) { + this.wsSocketSubject = new RxWebsocketSubject(this._baseURL); } public connect(): void { diff --git a/src/app/commons/router/state/serializer/simple-router-state-serializer.ts b/src/packages/commons/util/router/state/serializer/simple-router-state-serializer.ts similarity index 100% rename from src/app/commons/router/state/serializer/simple-router-state-serializer.ts rename to src/packages/commons/util/router/state/serializer/simple-router-state-serializer.ts diff --git a/src/packages/commons/rx/websocket/rx-websocket-subject.ts b/src/packages/commons/util/websocket/rx-websocket-subject.ts similarity index 100% rename from src/packages/commons/rx/websocket/rx-websocket-subject.ts rename to src/packages/commons/util/websocket/rx-websocket-subject.ts diff --git a/src/packages/member/service/member.service.ts b/src/packages/member/service/member.service.ts index 26bc9af..ab25d5b 100644 --- a/src/packages/member/service/member.service.ts +++ b/src/packages/member/service/member.service.ts @@ -3,7 +3,7 @@ import { Observable } from 'rxjs/Observable'; import 'rxjs/add/operator/map'; -import { RESTService } from 'app/commons/service/rest.service'; +import { RESTService } from 'packages/commons/service/rest.service'; import { Member } from '../model/member'; @@ -17,10 +17,15 @@ export class MemberService { } public signin(email: string, password: string): Observable { - return this.restService.post('/member/signin', '').map((member: Member) => member); + const body = { + signinId: email, + signinPw: password, + }; + + return this.restService.post('/account/signin', body); } public signup(member: Member): Observable { - return this.restService.post('/member/signup', '').map((_member: Member) => _member); + return this.restService.post('/account/signup', ''); } } diff --git a/src/packages/member/store/auth/auth.effect.ts b/src/packages/member/store/auth/auth.effect.ts index 5db6168..3315d9c 100644 --- a/src/packages/member/store/auth/auth.effect.ts +++ b/src/packages/member/store/auth/auth.effect.ts @@ -10,6 +10,7 @@ import { of } from 'rxjs/observable/of'; import 'rxjs/add/operator/catch'; import 'rxjs/add/operator/do'; import 'rxjs/add/operator/exhaustMap'; +import 'rxjs/add/operator/switchMap'; import 'rxjs/add/operator/map'; import 'rxjs/add/operator/take'; @@ -36,12 +37,25 @@ export class Effects { signin$: Observable = this.actions$ .ofType(ActionType.Signin) .map((action: Signin) => action.payload) - .exhaustMap(payload => - this.memberService - .signin(payload.email, payload.password) - .map(member => new SigninSuccess(member)) - .catch(error => of(new SigninFailure(error))) - ); + .switchMap(payload => this.memberService.signin(payload.email, payload.password)) + .map(member => { + return new SigninSuccess(member); + }) + .catch((error) => { + return of(new SigninFailure(error)); + }); + + // .map((action: Signin) => action.payload) + // .exhaustMap(payload => + // this.memberService + // .signin(payload.email, payload.password) + // .map(member => { + // return new SigninSuccess(member); + // }) + // .catch((error) => { + // return of(new SigninFailure(error.message)); + // }) + // ); @Effect({ dispatch: false }) signinSuccess$ = this.actions$ diff --git a/src/packages/member/store/auth/auth.reducer.ts b/src/packages/member/store/auth/auth.reducer.ts index d60b3d6..fd4c8a6 100644 --- a/src/packages/member/store/auth/auth.reducer.ts +++ b/src/packages/member/store/auth/auth.reducer.ts @@ -1,6 +1,7 @@ import { Actions, ActionType, + Signin, } from './auth.action'; import { diff --git a/yarn.lock b/yarn.lock index cec2f7b..c18ba11 100644 --- a/yarn.lock +++ b/yarn.lock @@ -291,6 +291,10 @@ version "0.0.30" resolved "https://registry.yarnpkg.com/@types/strip-json-comments/-/strip-json-comments-0.0.30.tgz#9aa30c04db212a9a0649d6ae6fd50accc40748a1" +"@types/url-join@^0.8.2": + version "0.8.2" + resolved "https://registry.yarnpkg.com/@types/url-join/-/url-join-0.8.2.tgz#1181ecbe1d97b7034e0ea1e35e62e86cc26b422d" + JSONStream@^1.0.3: version "1.3.2" resolved "https://registry.yarnpkg.com/JSONStream/-/JSONStream-1.3.2.tgz#c102371b6ec3a7cf3b847ca00c20bb0fce4c6dea" @@ -7273,6 +7277,10 @@ urix@^0.1.0: version "0.1.0" resolved "https://registry.yarnpkg.com/urix/-/urix-0.1.0.tgz#da937f7a62e21fec1fd18d49b35c2935067a6c72" +url-join@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/url-join/-/url-join-4.0.0.tgz#4d3340e807d3773bda9991f8305acdcc2a665d2a" + url-loader@^0.6.2: version "0.6.2" resolved "https://registry.yarnpkg.com/url-loader/-/url-loader-0.6.2.tgz#a007a7109620e9d988d14bce677a1decb9a993f7"