方案一:修改node_modules/realm/lib/browser/rpc.js
if (global.__debug__) {
let request = global.__debug__.require('sync-request');
let response = request('POST', url, {
body: JSON.stringify(data),
headers: {
"Content-Type": "text/plain;charset=UTF-8"
}
});
statusCode = response.statusCode;
responseText = response.body.toString('utf-8');
} else {
let body = JSON.stringify(data);
let request = new XMLHttpRequest();
// 增加以下代码
if (__DEV__) {
url = 'http://localhost:8083' + url.substring(url.lastIndexOf('/'));
}
request.open('POST', url, false);
request.send(body);
statusCode = request.status;
responseText = request.responseText;
}
方案二:修改RealmReactModule.java
两处
response.addHeader("Access-Control-Allow-Origin", "http://localhost:8081");
修改为
response.addHeader("Access-Control-Allow-Origin", "*");