fix preview proxy often using wrong url in standalone mode

This commit is contained in:
nightwing 2017-11-26 16:47:05 +04:00
parent d85d57ea9b
commit 843be092fd
3 changed files with 14 additions and 5 deletions

View File

@ -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",

View File

@ -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);

View File

@ -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()