Allowing app to run from sub path on the hostname

Signed-off-by: Srinivas Boga <bseenu@gmail.com>
This commit is contained in:
Srinivas Boga
2024-05-22 13:52:25 -07:00
parent e0e00bdb36
commit 2722efa556
3 changed files with 15 additions and 5 deletions

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;
@@ -90,6 +91,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,
};
@@ -102,10 +110,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;