From d85d57ea9b7a32983e53df74e1830cd78480ea2f Mon Sep 17 00:00:00 2001 From: das7pad Date: Sun, 12 Nov 2017 13:06:22 +0100 Subject: [PATCH 1/2] [plugins.c9.vfs.standalone] use current hostname for preview vfs-target --- plugins/c9.vfs.standalone/standalone.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/c9.vfs.standalone/standalone.js b/plugins/c9.vfs.standalone/standalone.js index 48955e9e..8cf365fb 100644 --- a/plugins/c9.vfs.standalone/standalone.js +++ b/plugins/c9.vfs.standalone/standalone.js @@ -142,7 +142,7 @@ function plugin(options, imports, register) { }, previewHandler.getProxyUrl(function() { return { - url: "http://localhost:" + options.options.port + "/vfs" + url: "http://" + options.options.host + ":" + options.options.port + "/vfs" }; }), previewHandler.proxyCall() From 843be092fdcdef71abf8eb34c664d2b22abf5f0b Mon Sep 17 00:00:00 2001 From: nightwing Date: Sun, 26 Nov 2017 16:47:05 +0400 Subject: [PATCH 2/2] fix preview proxy often using wrong url in standalone mode --- configs/standalone.js | 11 ++++++++--- plugins/c9.preview/preview.handler.js | 3 ++- plugins/c9.vfs.standalone/standalone.js | 5 ++++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/configs/standalone.js b/configs/standalone.js index df9358f1..fd27207f 100644 --- a/configs/standalone.js +++ b/configs/standalone.js @@ -41,7 +41,9 @@ module.exports = function(config, optimist) { .boolean("inProcessLocalFs") .describe("inProcessLocalFs", "Whether to run localfs in same process for debugging.") .default("inProcessLocalFs", config.inProcessLocalFs) - .boolean("useBrowserCache"); + .boolean("useBrowserCache") + .describe("useBrowserCache", "Use window.caches api if available for faster loading, requires https://") + .describe("secure", "path to file containing ssl certificate (can be generated using scripts/create-cert.sh)"); } var argv = optimist.argv; @@ -112,7 +114,7 @@ module.exports = function(config, optimist) { if (argv.secure) { var certPath = path.isAbsolute(argv.secure) ? argv.secure : path.join(__dirname, "..", argv.secure); - var key = require("fs").readFileSync(certPath , "utf8"); + var key = require("fs").readFileSync(certPath, "utf8"); config.secure = { key: key.match(/^(-+BEGIN RSA PRIVATE KEY[\s\S]*END RSA PRIVATE KEY-+)/m)[0], cert: key.match(/^(-+BEGIN CERTIFICATE[\s\S]*END CERTIFICATE-+)/m)[0], @@ -198,7 +200,10 @@ module.exports = function(config, optimist) { }, "./c9.vfs.server/vfs.server", "./c9.error/logger.raygun_noop", - "./c9.preview/preview.handler", + { + packagePath: "./c9.preview/preview.handler", + selfSignedSSL: config.secure + }, "./c9.vfs.server/cache", "./c9.vfs.server/download", "./c9.vfs.server/filelist", diff --git a/plugins/c9.preview/preview.handler.js b/plugins/c9.preview/preview.handler.js index d2e9839e..a5288db7 100644 --- a/plugins/c9.preview/preview.handler.js +++ b/plugins/c9.preview/preview.handler.js @@ -165,7 +165,8 @@ define(function(require, exports, module) { path: parsedUrl.path, hostname: parsedUrl.hostname, port: parsedUrl.port, - headers: req.headers + headers: req.headers, + rejectUnauthorized: !options.selfSignedSSL }, function(request) { if (request.statusCode >= 400 || request.headers["content-type"] == "text/x-error") handleError(request); diff --git a/plugins/c9.vfs.standalone/standalone.js b/plugins/c9.vfs.standalone/standalone.js index 8cf365fb..a1b64eca 100644 --- a/plugins/c9.vfs.standalone/standalone.js +++ b/plugins/c9.vfs.standalone/standalone.js @@ -141,8 +141,11 @@ function plugin(options, imports, register) { api.authenticate()(req, res, next); }, previewHandler.getProxyUrl(function() { + var serverOptions = options.options; + var host = serverOptions.host; + if (host == "0.0.0.0") host = "localhost"; return { - url: "http://" + options.options.host + ":" + options.options.port + "/vfs" + url: (serverOptions.secure ? "https://" : "http://") + host + ":" + serverOptions.port + "/vfs" }; }), previewHandler.proxyCall()