Skip to content

Commit

Permalink
[FIX] Protocol error when using https ui5.url
Browse files Browse the repository at this point in the history
Regression caused by #187

Fixes: #188
  • Loading branch information
matz3 committed May 25, 2020
1 parent c0642f0 commit 6396bb4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lib/framework.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ const normalizer = require("@ui5/project").normalizer;
const ui5Fs = require("@ui5/fs");
const resourceFactory = ui5Fs.resourceFactory;
const ReaderCollectionPrioritized = ui5Fs.ReaderCollectionPrioritized;
const {parse: parseUrl} = require("url");
const http = require("http");
const https = require("https");
const httpProxy = require("http-proxy");
const fs = require("fs");
const path = require("path");
Expand Down Expand Up @@ -441,7 +443,9 @@ class Framework {
}

setupProxy({url}) {
const agent = new http.Agent({keepAlive: true});
const {protocol} = parseUrl(url);
const Agent = protocol === "https:" ? https.Agent : http.Agent;
const agent = new Agent({keepAlive: true});
const proxy = httpProxy.createProxyServer({
target: url,
changeOrigin: true,
Expand Down
35 changes: 33 additions & 2 deletions test/unit/framework.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ describe("Middleware for UI5", () => {
});

describe("Proxy for UI5 ", () => {
it("Should call proxy module from serveResources middleware", (done) => {
it("Should call proxy module from serveResources middleware (http)", (done) => {
const proxyServer = new Framework().setupProxy({
url: "http://localhost"
});
Expand All @@ -152,7 +152,38 @@ describe("Proxy for UI5 ", () => {
target: "http://localhost",
changeOrigin: true,
agent: expect.objectContaining({
keepAlive: true
keepAlive: true,
protocol: "http:"
})
});

// const proxy = require("http-proxy").createProxyServer.mock.results[0].value;

expect(proxyServer.serveThemes).toBeUndefined();

const req = {};
const res = {};
const next = function() {
// expect(proxy.web).toBeCalledWith(req, res, next); // TODO: check why this fails
done();
};
proxyServer.serveResources(req, res, next);
});

it("Should call proxy module from serveResources middleware (https)", (done) => {
const proxyServer = new Framework().setupProxy({
url: "https://localhost"
});

const createProxyServer = require("http-proxy").createProxyServer;

const lastCall = createProxyServer.mock.calls[createProxyServer.mock.calls.length - 1];
expect(lastCall[0]).toMatchObject({
target: "https://localhost",
changeOrigin: true,
agent: expect.objectContaining({
keepAlive: true,
protocol: "https:"
})
});

Expand Down

0 comments on commit 6396bb4

Please sign in to comment.