Calling one app with ejs page as start page instead of index.html from electron-forge

时间:2018-11-27 00:56:02

标签: node.js ejs electron-forge

After installing electron-forge I create a /src folder to copy my app, the one I want to call from electron-forge

The code of electron-forge is:

  // and load the index.html of the app.
  mainWindow.loadURL(`file://${__dirname}/index.html`);

But my app didn't have index.html as start page.

The code of the app:

var express = require("express");
var app = express();

var request = require("request");

app.set("view engine", "ejs");

app.get("/", function(req, res) {
    res.render("search");
});

app.get("/results", function(req, res){

    var query = req.query.search;

    var url = "https://yts.am/api/v2/list_movies.json?sort=seeds&limit=15&query_term='" + query + "'";
    request(url, function(error, response, body){
        var data = JSON.parse(body);
        if(!error && response.statusCode == 200){
            //res.send(data["data"]["movies"][0]["title"]);
            res.render("results", {data: data});
            //["movies"][0]["title"]
        }
        else
        console.log(data);
    });
});

app.listen(3000, process.env.IP, function(){
    console.log("IMDB server has started on port 3000");
});

So if I change

  // and load the index.html of the app.
  mainWindow.loadURL(`file://${__dirname}/index.html`);

With something like:

  // and load the index.html of the app.
  mainWindow.loadURL(`file://${__dirname}/views/search.ejs`);

I see on the electron-forge window the code (text) of search.ejs but is not rendered as a HTML / Form page.

How can I Call one app with ejs page as start page?

0 个答案:

没有答案