Skip to content

Commit

Permalink
chore: sync develop and main branch
Browse files Browse the repository at this point in the history
  • Loading branch information
WojtekTheWebDev authored Jul 11, 2023
2 parents 925d3cc + 55fd24b commit 468c873
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 5 deletions.
52 changes: 51 additions & 1 deletion packages/core/__tests__/utils/nuxt/proxyUtils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,56 @@ describe('[CORE - utils] _proxyUtils', () => {
});
});

it('adds a X-Forwarded-Host header', () => {
const integrationConfig = utils.getIntegrationConfig(
{
$config: {
middlewareUrl: 'http://localhost.com'
},
req: {
headers: {
'x-forwarded-host': 'myforward.vsf'
}
}
} as any,
{}
);

expect(integrationConfig).toEqual({
axios: {
baseURL: expect.any(String),
headers: expect.objectContaining({
Host: 'myforward.vsf'
})
}
});
});

it('adds a Host header', () => {
const integrationConfig = utils.getIntegrationConfig(
{
$config: {
middlewareUrl: 'http://localhost.com'
},
req: {
headers: {
host: 'mywebsite.local'
}
}
} as any,
{}
);

expect(integrationConfig).toEqual({
axios: {
baseURL: expect.any(String),
headers: expect.objectContaining({
Host: 'mywebsite.local'
})
}
});
});

/**
* baseURL configuration cases matrix
*/
Expand All @@ -85,7 +135,7 @@ describe('[CORE - utils] _proxyUtils', () => {
];

const testMsg = '[baseUrl must be configured properly for] server: $server, middlewareUrl: $middlewareUrl, ssrMiddlewareUrl: $ssrMiddlewareUrl, expected: $expected';
test.each(urlSetupCases)(testMsg, ({ server, middlewareUrl, ssrMiddlewareUrl, expected }) => {
it.each(urlSetupCases)(testMsg, ({ server, middlewareUrl, ssrMiddlewareUrl, expected }) => {
process.server = server;

const integrationConfig = utils.getIntegrationConfig(
Expand Down
7 changes: 7 additions & 0 deletions packages/docs/changelog/6869.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
description: 'feat!: plugins pass X-Forwarded-Host header with fallback to the Host header in server to server communication #6869.',
link: 'https://github.com/vuestorefront/vue-storefront/pull/6869',
isBreaking: false,
author: 'Filip Jędrasik',
linkToGitHubAccount: 'https://github.com/Fifciu'
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import getAgnosticStatusCode, { ApolloError, AxiosError, UnknownError } from '..
import bigObject from '../test-data/getAgnosticStatusCode';

const expectedStatusCode = 400;
const defaultCode = 200;
const defaultCode = 500;
const networkErrorCode = 500;

describe('[middleware-helpers] getAgnosticStatusCode', () => {
Expand Down Expand Up @@ -30,7 +30,7 @@ describe('[middleware-helpers] getAgnosticStatusCode', () => {
});

it('retrieves the status code from big object', () => {
const testData = {...bigObject, ...{statusCode: expectedStatusCode}} as unknown as UnknownError;
const testData = { ...bigObject, ...{ statusCode: expectedStatusCode } } as unknown as UnknownError;
const statusCode = getAgnosticStatusCode(testData);

expect(statusCode).toBe(expectedStatusCode);
Expand Down
3 changes: 2 additions & 1 deletion packages/middleware/src/createServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ async function createServer(config: MiddlewareConfig): Promise<Express> {
const platformResponse = await apiFunction(...req.body);
res.send(platformResponse);
} catch (error) {
consola.error(error);
res.status(getAgnosticStatusCode(error));
res.send(error);
res.send('ServerError: Response not successful. Please, check server logs for more details.');
}
});

Expand Down
2 changes: 1 addition & 1 deletion packages/middleware/src/helpers/getAgnosticStatusCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function getAgnosticStatusCode(error: AxiosError | ApolloError | UnknownError):
return getAxiosStatusCode(error as AxiosError) ||
getApolloStatusCode(error as ApolloError) ||
obtainStatusCode(error as UnknownError) ||
200;
500;
}

export default getAgnosticStatusCode;

0 comments on commit 468c873

Please sign in to comment.