问题
I am very new to Electron, just tried to follow the Documentation.
I was able to run a html in Electron and it worked fine.
Then I tried to load a Rails app with BrowserWindow loadUrl, but the javascripts of the app are not working inside Electron.
My main is this index.js here:
var app = require ('app')
var BrowserWindow = require ('browser-window')
app.on('ready', function(){
var mainWindow = new BrowserWindow({
width:1115,
height:945
})
mainWindow.loadUrl('http://my-app-at-heroku.herokuapp.com')
})
Running the server in my machine and loading http://localhost:3000 has the same behavior. The app appears, but the js don't work.
What have I missed? How do I properly run a Rails app inside Electron?
回答1:
For future reference, the correct way to solve this is to set the "node-integration"
option on BrowserWindow to false
, like so:
var app = require ('app')
var BrowserWindow = require ('browser-window')
app.on('ready', function(){
var mainWindow = new BrowserWindow({
width:1115,
height:945,
"node-integration": false
})
mainWindow.loadUrl('http://my-app-at-heroku.herokuapp.com')
})
Source: https://github.com/atom/electron/issues/254#issuecomment-82322963
回答2:
I found out the solution.
In my Rails app, I had to include the following in the header:
<script type="text/javascript">
window.module = undefined;
window.require = undefined;
</script>
来源:https://stackoverflow.com/questions/31967854/how-to-properly-run-a-rails-app-inside-electron