Electron + express using main window and viewer window


#1

Hi again!
i’m developing my application that has two [at least] windows:
Main window has a bunch of filters, combo box and buttons to perform the query to my db
Viewer(s) window(s) in created when user press the OK button in the main window and perform the query to the sqlite database (so the user can create as many views he want, with different parameters)

i’m using Electron in conjunction with the sqlite3 module and ExpressJs for “server side” managing.

I’m able to perform the query and get all the data

restapi.get("/:datalog?",(req, res)=>{
var datalog=req.params.datalog;
 db.all("SELECT * FROM TABLE WHERE id="+datalog,function(err,row){
    res.render("home",{title:"Hey",rows:row});
  })
})

the rendering function points to an EJS template file, which works fine if i call it from the web browser. (http://localhost:3000/1234);
How can i create a new BrowserWindow in runtime that renders the result of the express call?!


#2

Make a function that creates a new BrowserWindow (with a global reference as seen in the quick start) and then call that function when you want to display the results. You should be able to have the reference variable be an array, so you could have your function create a new BrowserWindow at view[view.length].


#3

ok, i did it, but how i make the new page render the query result?
i’ve been trying with something like
> win[win.length] = new BrowserWindow({ … });
> win[win.length].loadURL(“http://localhost:3000/1234”)
> or
> win[win.length].loadURL(file://${__dirname}/file.ejs)

non of them seems to work. :confounded:


#4

ok, i’m sorry! :smiley:
i was mispelling the request. now seem to work.