diff --git a/src/ts/@overflow/app/config/index.ts b/src/ts/@overflow/app/config/index.ts index 1197fdf..6efc4e5 100644 --- a/src/ts/@overflow/app/config/index.ts +++ b/src/ts/@overflow/app/config/index.ts @@ -71,6 +71,14 @@ const rpcConfig: RPCConfig = { url: 'ws://127.0.0.1:19090/web', }; +// REST Server Configuration +export interface RestConfig { + url: string; +} +const restConfig: RestConfig = { + url: 'http://192.168.1.103:19080', +}; + // Redux Configuration export interface ReduxConfig { state: ReduxState; @@ -137,12 +145,14 @@ const reduxConfig: ReduxConfig = { export interface Config { container: ContainerConfig; rpc: RPCConfig; + rest: RestConfig; redux: ReduxConfig; } const config: Config = { container: containerConfig, rpc: rpcConfig, + rest: restConfig, redux: reduxConfig, }; diff --git a/src/ts/@overflow/app/index.tsx b/src/ts/@overflow/app/index.tsx index 201310b..0e17f7c 100644 --- a/src/ts/@overflow/app/index.tsx +++ b/src/ts/@overflow/app/index.tsx @@ -142,14 +142,15 @@ class OFApplication { OFApplication.useReduxDevTools ? compose(middleware, window.devToolsExtension()) : middleware, ); // saga - this.sagaMiddleware.run(this.initReduxSagaWarchers, this.config.redux.sagaWatchers, this.rpcClient); + this.sagaMiddleware.run(this.initReduxSagaWarchers, this.config, this.rpcClient); resolve(); }); return init; } - private * initReduxSagaWarchers(sagaWatchers: Class[], rpcClient: WebSocketRPC): SagaIterator { + private * initReduxSagaWarchers(config: Config, rpcClient: WebSocketRPC): SagaIterator { + let sagaWatchers: Class[] = config.redux.sagaWatchers; for (let type of sagaWatchers) { let instance = Object.create(type.prototype); @@ -157,6 +158,9 @@ class OFApplication { if (type.prototype.hasOwnProperty('setWebSocketRPC')) { instance.setWebSocketRPC.call(instance, rpcClient); } + if (type.prototype.hasOwnProperty('setRestUrl')) { + instance.setRestUrl.call(instance, config.rest.url); + } yield fork({context: instance, fn: instance.watch}); } } diff --git a/src/ts/@overflow/app/redux/saga/AsyncRestRequest.ts b/src/ts/@overflow/app/redux/saga/AsyncRestRequest.ts index e003058..5091b91 100644 --- a/src/ts/@overflow/app/redux/saga/AsyncRestRequest.ts +++ b/src/ts/@overflow/app/redux/saga/AsyncRestRequest.ts @@ -10,13 +10,13 @@ import AsyncRestRequestPayload from '@overflow/commons/redux/payload/AsyncRestRe import * as AppAsyncRestRequestSendingActions from '../action/asyncRestRequestSending'; export class AsyncRestRequest implements SagaWatcher { - // private _webSocketRPC: WebSocketRPC; - // - // public setWebSocketRPC(webSocketRPC: WebSocketRPC): void { - // this._webSocketRPC = webSocketRPC; - // } + private _restUrl: string; - private * request(action: Action): SagaIterator { + public setRestUrl(url: string): void { + this._restUrl = url; + } + + private * request(restUrl: string, action: Action): SagaIterator { const {entry, method, requestType, args} = action.payload; console.log(JSON.stringify(args)); @@ -25,7 +25,7 @@ export class AsyncRestRequest implements SagaWatcher { let result = yield call( fetch, - 'http://192.168.1.103:19080/account/' + entry, + restUrl + entry, { method: method, headers: { @@ -49,7 +49,7 @@ export class AsyncRestRequest implements SagaWatcher { } public * watch(): SagaIterator { - yield takeEvery(AsyncRestRequestActions.REQUEST, this.request); + yield takeEvery(AsyncRestRequestActions.REQUEST, this.request, this._restUrl); } public fetchApi2(uri: string, method:string, args:any): any {