How to properly run a Rails app inside Electron?

被刻印的时光 ゝ 提交于 2019-12-06 09:43:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!