Rest config has been added.
This commit is contained in:
parent
4d3647bfd2
commit
763ef41384
|
@ -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,
|
||||
};
|
||||
|
||||
|
|
|
@ -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});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue
Block a user