I want to show the content of my website in the appjs window, but I dont know how.
In the appjs script there are
app.serveFilesFrom(__dirname + '/content');
to say where the content is, that it has to show, but I dont want it local, I want it to show the content of my website, running by a node.js serverscript.
I have tried this https://github.com/appjs/appjs/wiki/Using-express-to-handle-local-http-requests and some of the methods from the express.js documentation but unsuccessfully.
Therefore I ask here, have somebody an idea, how to do this?
I hope I understood your question correctly, you can actually make a proxy request and pipe it's response to your app response.
var http = require("http");
var express = require("express");
var app = express();
var options = {
host: "stackoverflow.com",
port: 80,
path: "/",
method: "GET",
headers: {}
};
app.get("/stackoverflow*", function (request, response) {
"use strict";
var proxyRequest;
options.headers.cookie = request.headers.cookie;
options.headers["user-agent"] = request.headers["user-agent"];
// TODO set other headers if needed
options.path = "/" + request.path.split("/").slice(2).join("/");
options.method = request.method;
proxyRequest = http.request(options, function (proxyResponse) {
proxyResponse.pipe(response);
});
request.pipe(proxyRequest);
}).listen(8080);
Now you can navigate to http://localhost:8080/stackoverflow/questions/14880557/how-to-connect-appjs-to-nodejs-server-and-show-its-content/14890268#14890268 and your app will show the requested path from stackoverflow.com.
To have you website displayed within AppJS window like a web browser, which is one of the primary intents of AppJS, you can take any one of these two (2) steps;
Create an IFRAME (that fills up the width and height) in the index.html file located at "data/content/".
Set the IFRAME SRC to your website url.
e.g. < iframe src="http://www.YourWebsite.com">
This will display your website in AppJS window when app.exe is started.
NOTE: You might want to use CSS to make the iframe fill up 100% width and 100% height of the window.
Change the line of code at "data/node_modules/appjs/lib/settings.js"
FROM
url :'ht tp://appjs',
TO
url: 'http://www.YourWebsite.com'
Most of the time I opt for the first option as it allows me do a whole lot of things using CSS. And this includes placing an animated GIF at the background of the IFRAME to indicate page loading at start up.
I go for the second option only when I want to make my actual website url a little trickier to find during an attempted hack. While still leaving the "data/content" directory and its content undeleted.
I hope this answers.