2017-09-08 29 views
0

嘗試使用ember-electron構建Electron應用,並試圖使用emberfire與Firebase進行通信。無法從電子應用內訪問Firebase

XMLHttpRequest cannot load https://www.googleapis.com/identitytoolkit/v3/relyingparty/signupNewUser?key=AIzaSyBYyuJ-1E3ufujlzdKhj8gE9I6QH8TreJE. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'serve://dist' is therefore not allowed access. The response had HTTP status code 404. 

這是一個已知的問題還是沒有人知道解決的辦法:一切都與ember s一個web應用程序運行,但作爲電子應用推出時,我什麼也沒得到,但象這樣的錯誤,當運行正常?遺憾的是,不能簡單地將serve://dist添加到授權域名列表中,因爲Google並不認爲它是有效的域名。

更新:我還是很想知道如果任何人有一個可能的解決方法,但我發現了一個名爲Nativefier(https://github.com/jiahaog/nativefier)工具,它適合我的目的。由於我同時開發Web應用程序和桌面應用程序,一旦託管了Web應用程序,就可以使用本地應用程序構建桌面應用程序。

回答

0

我沒有嘗試使用電子,而是使用node-webkit。許多與原產地有關的問題可以通過運行本地網絡服務器來解決:在主要腳本中運行一個使用快遞服務你的應用程序的網絡服務器。這是一段代碼,我用它來啓動本地服務器:

let express = require('express'); 
let http = require('http'); 
let app = express(); 
app.use('/', express.static('dist')); 
let server = http.createServer(app); 
let port = 9000; 
let maxPort = 50000; 
server.on('error', function (e) { 
    if (port < maxPort) { 
     server.listen(++port); 
    } else { 
     alert('Your system has no free ports to start a web-server, which is needed for this app to work'); 
     window.nw.Window.get().close(); 
    } 
}); 
server.on('listening', function() { 
    location = 'http://localhost:' + port + '/index.html'; 
}); 
server.listen(port); 

我認爲類似的東西應該爲電子工作,太