Merge pull request #455 from bseenu/ROOT_PATH

Allowing app to run from sub path on the hostname
This commit is contained in:
Sihan(Arthur) Tu
2024-06-29 20:57:37 -07:00
committed by GitHub
3 changed files with 15 additions and 5 deletions

1
client/.env Normal file
View File

@@ -0,0 +1 @@
REACT_APP_ROOT_PATH = $ROOT_PATH

View File

@@ -19,10 +19,11 @@ type StreamArgs = {
connectCb?: () => void;
}
const ROOT_PATH = process.env.REACT_APP_ROOT_PATH || '';
const {hostname, href, hash, search} = window.location;
const nonHashedUrl = href.replace(hash, '').replace(search, '').replace('#', '');
const isDev = process.env.NODE_ENV !== 'production';
const BASE_HTTP_URL = isDev && hostname === 'localhost' ? 'http://localhost:4654' : nonHashedUrl;
const BASE_HTTP_URL = isDev && hostname === 'localhost' ? `http://localhost:4654${ROOT_PATH}` : `${nonHashedUrl}${ROOT_PATH}`;
const BASE_WS_URL = BASE_HTTP_URL.replace('http', 'ws');
const JSON_HEADERS = {Accept: 'application/json', 'Content-Type': 'application/json'};
const PROTO_HEADERS = {Accept: 'application/vnd.kubernetes.protobuf', 'Content-Type': 'application/json'};

View File

@@ -16,6 +16,7 @@ const crypto = getCrypto();
const NODE_ENV = process.env.NODE_ENV;
const DEBUG_VERBOSE = !!process.env.DEBUG_VERBOSE;
const ROOT_PATH = process.env.ROOT_PATH || '';
const OIDC_CLIENT_ID = process.env.OIDC_CLIENT_ID;
const OIDC_SECRET = process.env.OIDC_SECRET;
const OIDC_URL = process.env.OIDC_URL;
@@ -91,6 +92,13 @@ const proxySettings = {
ws: true,
secure: false,
changeOrigin: true,
// remove the root_path for the calls which are being proxied to k8s api server
pathRewrite: function (path, req) {
if (ROOT_PATH) {
return path.replace(`${ROOT_PATH}`, '');
}
return path;
},
logLevel: 'debug',
onError,
};
@@ -103,10 +111,10 @@ const app = express();
app.disable('x-powered-by'); // for security reasons, best not to tell attackers too much about our backend
app.use(logging);
if (NODE_ENV !== 'production') app.use(cors());
app.use('/', preAuth, express.static('public'));
app.get('/oidc', getOidc);
app.post('/oidc', postOidc);
app.use('/*', createProxyMiddleware(proxySettings));
app.use(ROOT_PATH, preAuth, express.static('public'));
app.get(ROOT_PATH + '/oidc', getOidc);
app.post(ROOT_PATH + '/oidc', postOidc);
app.use(ROOT_PATH, createProxyMiddleware(proxySettings));
app.use(handleErrors);
const port = process.env.SERVER_PORT || 4654;