Skip to content

Instantly share code, notes, and snippets.

@smile921
Created April 12, 2017 01:59
Show Gist options
  • Save smile921/90ed1aff40b5cb4707bd0c4d8ccf8000 to your computer and use it in GitHub Desktop.
Save smile921/90ed1aff40b5cb4707bd0c4d8ccf8000 to your computer and use it in GitHub Desktop.
use web3 but find cors problem
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
});
import Ember from 'ember';
import web3 from 'ember-web3/services/web3';
export default Ember.Route.extend({
host:'http://112.64.159.162:10005',
web3:Ember.inject.service(),
model(){
let web3 = new Web3(new Web3.providers.HttpProvider('http://112.64.159.162:10005'));
return web3.version;
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
<p>{{host}}</p>
<p> {{model.ethereum}}</p>
<p>{{model.node}} </p>
<p>{{model.api}} </p>
<p>{{model.network}} </p>
{
"version": "0.12.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.12.0",
"ember-template-compiler": "2.12.0",
"ember-testing": "2.12.0"
},
"addons": {
"ember-web3": "0.0.9",
"ember-data": "2.12.1"
}
}
@smile921
Copy link
Author

image

当我使用 Ember-web3 时 ,发现这个跨域问题,不知道如何处理

XMLHttpRequest cannot load http://127.0.0.1:8545/. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:8080' is therefore not allowed access.

ember.debug.js:18008 Error: CONNECTION ERROR: Couldn't connect to node http://127.0.0.1:8545.
    at Object.InvalidConnection (web3.min.js:1)
    at i.send (web3.min.js:2)
    at s.send (web3.min.js:2)
    at Object.node (web3.min.js:2)
    at Object.watchKey (ember.debug.js:23572)
    at NestedPropertyReference.compute (ember.debug.js:15395)
    at NestedPropertyReference.value (ember.debug.js:15212)
    at GuardedCautiousAppendOpcode.evaluate (ember.debug.js:48076)
    at VM.execute (ember.debug.js:54370)
    at VM.resume (ember.debug.js:54349)
defaultDispatch @ ember.debug.js:18008
dispatchError @ ember.debug.js:17987
invokeWithOnError @ ember.debug.js:349
flush @ ember.debug.js:405
flush @ ember.debug.js:529
end @ ember.debug.js:599
run @ ember.debug.js:713
_runExpiredTimers @ ember.debug.js:1107
Backburner._boundRunExpiredTimers @ ember.debug.js:568

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment