Rest config has been added.

This commit is contained in:
crusader 2017-09-04 19:28:04 +09:00
parent 4d3647bfd2
commit 763ef41384
3 changed files with 24 additions and 10 deletions

View File

@ -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,
};

View File

@ -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<SagaWatcher>[], rpcClient: WebSocketRPC): SagaIterator {
private * initReduxSagaWarchers(config: Config, rpcClient: WebSocketRPC): SagaIterator {
let sagaWatchers: Class<SagaWatcher>[] = 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});
}
}

View File

@ -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<AsyncRestRequestPayload>): SagaIterator {
public setRestUrl(url: string): void {
this._restUrl = url;
}
private * request(restUrl: string, action: Action<AsyncRestRequestPayload>): 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 {