From 5bfd5305077c35fdd5e71cf0f6ae4d0f58661c40 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 11 Dec 2023 12:29:23 -0500 Subject: [PATCH] fix(requests): use relative request paths (#1175) (#1179) * use relative authority * use relative request path (cherry picked from commit 991011f5d45ad1a145b5f2cd177ab91a5b7f6e13) Co-authored-by: Andrew Azores --- src/app/Shared/Services/Login.service.tsx | 2 +- src/index.html | 2 +- src/mirage/index.ts | 2 +- src/test/Shared/Services/Login.service.test.tsx | 10 +++++----- webpack.common.js | 3 +-- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/app/Shared/Services/Login.service.tsx b/src/app/Shared/Services/Login.service.tsx index b629acafc..46135fb19 100644 --- a/src/app/Shared/Services/Login.service.tsx +++ b/src/app/Shared/Services/Login.service.tsx @@ -40,7 +40,7 @@ export class LoginService { private readonly authCredentials: AuthCredentials, private readonly settings: SettingsService, ) { - this.authority = process.env.CRYOSTAT_AUTHORITY || ''; + this.authority = process.env.CRYOSTAT_AUTHORITY || '.'; this.token.next(this.getCacheItem(this.TOKEN_KEY)); this.username.next(this.getCacheItem(this.USER_KEY)); this.authMethod.next(this.getCacheItem(this.AUTH_METHOD_KEY) as AuthMethod); diff --git a/src/index.html b/src/index.html index fbd8f87cd..ef1490f82 100644 --- a/src/index.html +++ b/src/index.html @@ -21,7 +21,7 @@ Cryostat - + diff --git a/src/mirage/index.ts b/src/mirage/index.ts index 00077808e..67ea01684 100644 --- a/src/mirage/index.ts +++ b/src/mirage/index.ts @@ -399,7 +399,7 @@ export const startMirage = ({ environment = 'development' } = {}) => { }, ]); this.get('api/v2/probes', () => []); - this.post('/api/beta/matchExpressions', (_, request) => { + this.post('api/beta/matchExpressions', (_, request) => { const attr = JSON.parse(request.requestBody); if (!attr.matchExpression || !attr.targets) { return new Response(400); diff --git a/src/test/Shared/Services/Login.service.test.tsx b/src/test/Shared/Services/Login.service.test.tsx index 718b9d883..1c55cbe4f 100644 --- a/src/test/Shared/Services/Login.service.test.tsx +++ b/src/test/Shared/Services/Login.service.test.tsx @@ -117,7 +117,7 @@ describe('Login.service', () => { it('should make expected API calls', async () => { await firstValueFrom(svc.setLoggedOut()); expect(mockFromFetch).toHaveBeenCalledTimes(3); - expect(mockFromFetch).toHaveBeenNthCalledWith(2, `/api/v2.1/auth`, { + expect(mockFromFetch).toHaveBeenNthCalledWith(2, `./api/v2.1/auth`, { credentials: 'include', mode: 'cors', method: 'POST', @@ -126,7 +126,7 @@ describe('Login.service', () => { Authorization: `Basic dXNlcjpkNzRmZjBlZThkYTNiOTgwNmIxOGM4NzdkYmYyOWJiZGU1MGI1YmQ4ZTRkYWQ3YTNhNzI1MDAwZmViODJlOGYx`, }), }); - expect(mockFromFetch).toHaveBeenNthCalledWith(3, `/api/v2.1/logout`, { + expect(mockFromFetch).toHaveBeenNthCalledWith(3, `./api/v2.1/logout`, { credentials: 'include', mode: 'cors', method: 'POST', @@ -230,7 +230,7 @@ describe('Login.service', () => { it('should make expected API calls', async () => { await firstValueFrom(svc.setLoggedOut()); expect(mockFromFetch).toHaveBeenCalledTimes(3); - expect(mockFromFetch).toHaveBeenNthCalledWith(1, `/api/v2.1/auth`, { + expect(mockFromFetch).toHaveBeenNthCalledWith(1, `./api/v2.1/auth`, { credentials: 'include', mode: 'cors', method: 'POST', @@ -239,7 +239,7 @@ describe('Login.service', () => { Authorization: `Bearer c2hhMjU2fmhlbGxvd29ybGQ`, }), }); - expect(mockFromFetch).toHaveBeenNthCalledWith(2, `/api/v2.1/logout`, { + expect(mockFromFetch).toHaveBeenNthCalledWith(2, `./api/v2.1/logout`, { credentials: 'include', mode: 'cors', method: 'POST', @@ -248,7 +248,7 @@ describe('Login.service', () => { Authorization: `Bearer c2hhMjU2fmhlbGxvd29ybGQ`, }), }); - expect(mockFromFetch).toHaveBeenNthCalledWith(3, `/api/v2.1/auth`, { + expect(mockFromFetch).toHaveBeenNthCalledWith(3, `./api/v2.1/auth`, { credentials: 'include', mode: 'cors', method: 'POST', diff --git a/webpack.common.js b/webpack.common.js index 37d95ac2c..27682b1d9 100644 --- a/webpack.common.js +++ b/webpack.common.js @@ -3,7 +3,6 @@ const HtmlWebpackPlugin = require('html-webpack-plugin'); const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin'); const BG_IMAGES_DIRNAME = 'bgimages'; -const ASSET_PATH = process.env.ASSET_PATH || '/'; module.exports = (env) => { return { @@ -154,7 +153,7 @@ module.exports = (env) => { chunkFilename: '[id].[contenthash].bundle.js', // lazy-load modules hashFunction: "xxhash64", path: path.resolve(__dirname, 'dist'), - publicPath: ASSET_PATH, + publicPath: 'auto', clean: true }, resolve: {