Skip to content

Commit

Permalink
Change to API_PROXY=http://localhost:5001 instead of API_PROXY_HOST &…
Browse files Browse the repository at this point in the history
… API_PROXY_PORT (ansible#5381)

to allow running against https backends

and ignore self-signed https certificates,
and spoof the Origin, Host & Referer headers correctly

(cherry picked from commit 7b57440)
  • Loading branch information
himdel committed Jan 3, 2025
1 parent c0ac769 commit 38079cf
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ cd ansible-hub-ui
npm run start-standalone
```

(Or `API_PROXY=http://localhost:5001 npm run start-standalone`; run `API_PROXY=https://my-server.example.com npm run start-standalone` to run with external backend.)

Standalone mode only requires a running instance of the galaxy API for the UI to connect to.


Expand Down
20 changes: 10 additions & 10 deletions config/standalone.dev.webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const webpackBase = require('./webpack.base.config');
const { webpackBase, proxy } = require('./webpack.base.config');

// Used for getting the correct host when running in a container
const proxyHost = process.env.API_PROXY_HOST || 'localhost';
const proxyPort = process.env.API_PROXY_PORT || '55001';
const proxyTarget = process.env.API_PROXY || 'http://localhost:55001';

const apiBasePath = process.env.API_BASE_PATH || '/api/galaxy/';
const uiExternalLoginURI = process.env.UI_EXTERNAL_LOGIN_URI || '/login';

Expand All @@ -28,11 +28,11 @@ module.exports = webpackBase({
// Value for webpack.devServer.proxy
// https://webpack.js.org/configuration/dev-server/#devserverproxy
// used to get around CORS requirements when running in dev mode
WEBPACK_PROXY: {
'/api/': `http://${proxyHost}:${proxyPort}`,
'/pulp/api/': `http://${proxyHost}:${proxyPort}`,
'/v2/': `http://${proxyHost}:${proxyPort}`,
'/extensions/v2/': `http://${proxyHost}:${proxyPort}`,
'/static/rest_framework/': `http://${proxyHost}:${proxyPort}`,
},
WEBPACK_PROXY: [
proxy('/api/', proxyTarget),
proxy('/pulp/api/', proxyTarget),
proxy('/v2/', proxyTarget),
proxy('/extensions/v2/', proxyTarget),
proxy('/static/rest_framework/', proxyTarget),
],
});
2 changes: 1 addition & 1 deletion config/standalone.prod.webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const webpackBase = require('./webpack.base.config');
const { webpackBase } = require('./webpack.base.config');

// Compile configuration for stnadalone mode
module.exports = webpackBase({
Expand Down
21 changes: 20 additions & 1 deletion config/webpack.base.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,21 @@ const defaultConfigs = [
{ name: 'WEBPACK_PUBLIC_PATH', default: undefined, scope: 'webpack' },
];

module.exports = (inputConfigs) => {
const proxy = (route, target) => {
const u = new URL(target);
return {
context: [route],
target,
secure: false,
router: (req) => {
req.headers.host = u.host;
req.headers.origin = u.origin;
req.headers.referer = u.href;
},
};
};

const webpackBase = (inputConfigs) => {
const customConfigs = {};
const globals = {};

Expand Down Expand Up @@ -167,3 +181,8 @@ module.exports = (inputConfigs) => {
},
};
};

module.exports = {
proxy,
webpackBase,
};

0 comments on commit 38079cf

Please sign in to comment.