
Introduction:
We are doing a new research project recently with node-webkit see the above picture. Where node-webkit loads a simple https web url where we have all our nodejs scripts to access serial port, java-applets, tcp/udp etc etc to send and receive commands from a robot. after receiving all those information we need to send them to server, server does all the management and do a proper interpretation for the other robots to simulate same actions.
Problem:
But the node-webkit limitation is killing our project deadline because its not allowing very basic access when we load the pages using https / http instead of local.
We have our closed source code in cloud servers, all the node-webkit runs in Local machine and executes the web page as https://load-from-server, now we place all our device access codes in remote server instead of local and we need to have full access on that PC just like if you had the script executed locally. We also require this because our remote scripts get automatically upto date.
How can we make this possible in node-webkit, its a very important requirement for our use case but i have not found any solution for it yet.
Question: How can i tell node-webkit that following lines if loaded via https or http from remote server run them as it was running well using local index.html?
var gui = require('nw.gui');
var sys = require('sys')
var exec = require('child_process').exec;
var os = require('os');
var win = gui.Window.get();
Are you loading index.html from an IFRAME ?
NO - loading the index.html from https://www.remoteserver.com/index.html, as normal url
try to use the index.html from local, and including scripts from https://load-from-server
That is the problem, we can not use index.html from local for many use policy.
We need to use the index.html as https://load-from-server and have the same feature like running it from local index.html.
Is there any way use index.html locally but on the fly get the latest versions of nodejs script which can be injected from HTTPS SERVER at-least so that we do not have to always modify the index.html?
if your index.html is a file you can make it included just a loader.js hosted remotely.
the loader.js after can use jquery $.getScript() function to inject other js.
In this way you have not to update the local index.html
@gseregni, thank you, i will try this one, if this works as you have explained then it will resolve our problem.
@shamun: unless I'm misunderstanding your requirements, your problem should be easily solvable by providing the appropriate node-remote key in your manifest.
Assuming that your app lives on https://production.com you could do something like the following:
To be shipped with the NW binaries, either standalone or packaged by itself inside app.nw, or similar.
{
"name": "claw-client",
"main": "https://production.com",
"node-remote": "https://production.com"
}
:warning: DANGER: node-remote can be dangerous if mis-used/configured. You should be as granular as possible when specifying which sources should have remote execution privileges.
Located in /.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Claw App</title>
</head>
<body>
<!-- OK as long as the origin satisfies one of the `node-remote` rules in your manifest. -->
<script src="app.js"></script>
</body>
</html>
Located in /.
// Shows usage in different JS contexts.
document.addEventListener('DOMContentLoaded', function() {
// Native UI.
require('nw.gui').Window.get().resizeTo(320, 320);
// Core Node module.
var uptime = Math.floor(require('os').uptime());
// DOM.
document.write('Server up for: ' + uptime + ' seconds');
});
yeah. you can use node-remote
and please submit questions to the mailing list or stackoverflow.
has the same question!And I am also confusing about how to require local node
modules~
if my main is "/source/index.html", I can require local module which is start from "/source"
but if my main is "http://test.com/test/index.html", how can I require my local node module
Most helpful comment
@shamun: unless I'm misunderstanding your requirements, your problem should be easily solvable by providing the appropriate
node-remotekey in your manifest.Assuming that your app lives on
https://production.comyou could do something like the following:Client
package.json
To be shipped with the NW binaries, either standalone or packaged by itself inside
app.nw, or similar.:warning: DANGER:
node-remotecan be dangerous if mis-used/configured. You should be as granular as possible when specifying which sources should have remote execution privileges.Server
index.html
Located in
/.app.js
Located in
/.