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',
|
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
|
// Redux Configuration
|
||||||
export interface ReduxConfig {
|
export interface ReduxConfig {
|
||||||
state: ReduxState;
|
state: ReduxState;
|
||||||
|
@ -137,12 +145,14 @@ const reduxConfig: ReduxConfig = {
|
||||||
export interface Config {
|
export interface Config {
|
||||||
container: ContainerConfig;
|
container: ContainerConfig;
|
||||||
rpc: RPCConfig;
|
rpc: RPCConfig;
|
||||||
|
rest: RestConfig;
|
||||||
redux: ReduxConfig;
|
redux: ReduxConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
const config: Config = {
|
const config: Config = {
|
||||||
container: containerConfig,
|
container: containerConfig,
|
||||||
rpc: rpcConfig,
|
rpc: rpcConfig,
|
||||||
|
rest: restConfig,
|
||||||
redux: reduxConfig,
|
redux: reduxConfig,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -142,14 +142,15 @@ class OFApplication {
|
||||||
OFApplication.useReduxDevTools ? compose(middleware, window.devToolsExtension()) : middleware,
|
OFApplication.useReduxDevTools ? compose(middleware, window.devToolsExtension()) : middleware,
|
||||||
);
|
);
|
||||||
// saga
|
// saga
|
||||||
this.sagaMiddleware.run(this.initReduxSagaWarchers, this.config.redux.sagaWatchers, this.rpcClient);
|
this.sagaMiddleware.run(this.initReduxSagaWarchers, this.config, this.rpcClient);
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
|
|
||||||
return init;
|
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) {
|
for (let type of sagaWatchers) {
|
||||||
|
|
||||||
let instance = Object.create(type.prototype);
|
let instance = Object.create(type.prototype);
|
||||||
|
@ -157,6 +158,9 @@ class OFApplication {
|
||||||
if (type.prototype.hasOwnProperty('setWebSocketRPC')) {
|
if (type.prototype.hasOwnProperty('setWebSocketRPC')) {
|
||||||
instance.setWebSocketRPC.call(instance, rpcClient);
|
instance.setWebSocketRPC.call(instance, rpcClient);
|
||||||
}
|
}
|
||||||
|
if (type.prototype.hasOwnProperty('setRestUrl')) {
|
||||||
|
instance.setRestUrl.call(instance, config.rest.url);
|
||||||
|
}
|
||||||
yield fork({context: instance, fn: instance.watch});
|
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';
|
import * as AppAsyncRestRequestSendingActions from '../action/asyncRestRequestSending';
|
||||||
|
|
||||||
export class AsyncRestRequest implements SagaWatcher {
|
export class AsyncRestRequest implements SagaWatcher {
|
||||||
// private _webSocketRPC: WebSocketRPC;
|
private _restUrl: string;
|
||||||
//
|
|
||||||
// public setWebSocketRPC(webSocketRPC: WebSocketRPC): void {
|
|
||||||
// this._webSocketRPC = webSocketRPC;
|
|
||||||
// }
|
|
||||||
|
|
||||||
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;
|
const {entry, method, requestType, args} = action.payload;
|
||||||
console.log(JSON.stringify(args));
|
console.log(JSON.stringify(args));
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ export class AsyncRestRequest implements SagaWatcher {
|
||||||
|
|
||||||
let result = yield call(
|
let result = yield call(
|
||||||
fetch,
|
fetch,
|
||||||
'http://192.168.1.103:19080/account/' + entry,
|
restUrl + entry,
|
||||||
{
|
{
|
||||||
method: method,
|
method: method,
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -49,7 +49,7 @@ export class AsyncRestRequest implements SagaWatcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
public * watch(): SagaIterator {
|
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 {
|
public fetchApi2(uri: string, method:string, args:any): any {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user