Skip to content

Commit

Permalink
[FIX] Improve performance when serving UI5 resources via URL
Browse files Browse the repository at this point in the history
Using an agent with "keepAlive" improves performance when proxing
requests, especially on Windows.
  • Loading branch information
matz3 committed May 19, 2020
1 parent e9af1b5 commit 20b6512
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 4 additions & 1 deletion lib/framework.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const normalizer = require("@ui5/project").normalizer;
const ui5Fs = require("@ui5/fs");
const resourceFactory = ui5Fs.resourceFactory;
const ReaderCollectionPrioritized = ui5Fs.ReaderCollectionPrioritized;
const http = require("http");
const httpProxy = require("http-proxy");
const fs = require("fs");
const path = require("path");
Expand Down Expand Up @@ -440,9 +441,11 @@ class Framework {
}

setupProxy({url}) {
const agent = new http.Agent({keepAlive: true});
const proxy = httpProxy.createProxyServer({
target: url,
changeOrigin: true
changeOrigin: true,
agent
});

return {
Expand Down
8 changes: 6 additions & 2 deletions test/unit/framework.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,13 @@ describe("Proxy for UI5 ", () => {

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

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

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

0 comments on commit 20b6512

Please sign in to comment.