我正在使用 fetch ,如此处所示(使用 fetch 而不是 ajax 和 redux-observable)在服务器端使用节点进行 fetch。不幸的是,AjaxObservable 只能在浏览器中工作,所以我使用 isomorphic-fetch 在服务器上进行 fetch。
我的代码看起来像这样:
let fetch$ = null;
if (canUseDOM) {
fetch$ = AjaxObservable.create({
url,
method: 'GET',
responseType: 'json',
...options
}).takeUntil(action$.ofType(`${type}_CANCEL`));
} else {
fetch$ = Observable.from(fetch(url, options).then(response => {
return response.json()
}).then(response => ({response})));
}
return fetch$
.map(({response: payload}) => ({type, payload}))
但是,当我在服务器(即canUseDOM == false
)上运行它时,我收到以下错误:
RangeError: Maximum call stack size exceeded
at SafeSubscriber.Subscription.unsubscribe (/Users/bmonro/Documents/Code/nui-redux/ext/@concur/nui-middleware/node_modules/rxjs/Subscription.js:79:19)
at SafeSubscriber.Subscriber.unsubscribe (/Users/bmonro/Documents/Code/nui-redux/ext/@concur/nui-middleware/node_modules/rxjs/Subscriber.js:122:38)
at SafeSubscriber.__tryOrUnsub (/Users/bmonro/Documents/Code/nui-redux/ext/@concur/nui-middleware/node_modules/rxjs/Subscriber.js:226:18)
at SafeSubscriber.next (/Users/bmonro/Documents/Code/nui-redux/ext/@concur/nui-middleware/node_modules/rxjs/Subscriber.js:172:22)
at Subscriber._next (/Users/bmonro/Documents/Code/nui-redux/ext/@concur/nui-middleware/node_modules/rxjs/Subscriber.js:125:26)
at Subscriber.next (/Users/bmonro/Documents/Code/nui-redux/ext/@concur/nui-middleware/node_modules/rxjs/Subscriber.js:89:18)
at SwitchMapSubscriber.notifyNext (/Users/bmonro/Documents/Code/nui-redux/ext/@concur/nui-middleware/node_modules/rxjs/operator/switchMap.js:77:30)
at InnerSubscriber._next (/Users/bmonro/Documents/Code/nui-redux/ext/@concur/nui-middleware/node_modules/rxjs/InnerSubscriber.js:23:21)
at InnerSubscriber.Subscriber.next (/Users/bmonro/Documents/Code/nui-redux/ext/@concur/nui-middleware/node_modules/rxjs/Subscriber.js:89:18)
at MergeMapSubscriber.notifyNext (/Users/bmonro/Documents/Code/nui-redux/ext/@concur/nui-middleware/node_modules/rxjs/operator/mergeMap.js:85:30)