🛂(backend) stop throttling collaboration servers
We observe some throttling pick here and there. We observed that when the collaboration has a problem, it is retrying to connect, leading to more requests to the django backend. At one point, the throttling is reached and the user would not be able to use the application anymore. Now when the request comes from a collaboration server, we do not throttle it anymore.
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
import axios from 'axios';
|
||||
import { describe, expect, test, vi } from 'vitest';
|
||||
|
||||
vi.mock('../src/env', () => ({
|
||||
COLLABORATION_BACKEND_BASE_URL: 'http://app-dev:8000',
|
||||
Y_PROVIDER_API_KEY: 'test-yprovider-key',
|
||||
}));
|
||||
|
||||
describe('CollaborationBackend', () => {
|
||||
test('fetchDocument sends X-Y-Provider-Key header', async () => {
|
||||
const axiosGetSpy = vi.spyOn(axios, 'get').mockResolvedValue({
|
||||
status: 200,
|
||||
data: {
|
||||
id: 'test-doc-id',
|
||||
abilities: { retrieve: true, update: true },
|
||||
},
|
||||
});
|
||||
|
||||
const { fetchDocument } = await import('@/api/collaborationBackend');
|
||||
const documentId = 'test-document-123';
|
||||
|
||||
await fetchDocument(documentId, { cookie: 'test-cookie' });
|
||||
|
||||
expect(axiosGetSpy).toHaveBeenCalledWith(
|
||||
`http://app-dev:8000/api/v1.0/documents/${documentId}/`,
|
||||
expect.objectContaining({
|
||||
headers: expect.objectContaining({
|
||||
'X-Y-Provider-Key': 'test-yprovider-key',
|
||||
cookie: 'test-cookie',
|
||||
}),
|
||||
}),
|
||||
);
|
||||
|
||||
axiosGetSpy.mockRestore();
|
||||
});
|
||||
|
||||
test('fetchCurrentUser sends X-Y-Provider-Key header', async () => {
|
||||
const axiosGetSpy = vi.spyOn(axios, 'get').mockResolvedValue({
|
||||
status: 200,
|
||||
data: {
|
||||
id: 'test-user-id',
|
||||
email: 'test@example.com',
|
||||
},
|
||||
});
|
||||
|
||||
const { fetchCurrentUser } = await import('@/api/collaborationBackend');
|
||||
|
||||
await fetchCurrentUser({
|
||||
cookie: 'test-cookie',
|
||||
origin: 'http://localhost:3000',
|
||||
});
|
||||
|
||||
expect(axiosGetSpy).toHaveBeenCalledWith(
|
||||
'http://app-dev:8000/api/v1.0/users/me/',
|
||||
expect.objectContaining({
|
||||
headers: expect.objectContaining({
|
||||
'X-Y-Provider-Key': 'test-yprovider-key',
|
||||
cookie: 'test-cookie',
|
||||
origin: 'http://localhost:3000',
|
||||
}),
|
||||
}),
|
||||
);
|
||||
|
||||
axiosGetSpy.mockRestore();
|
||||
});
|
||||
});
|
||||
@@ -2,7 +2,7 @@ import { IncomingHttpHeaders } from 'http';
|
||||
|
||||
import axios from 'axios';
|
||||
|
||||
import { COLLABORATION_BACKEND_BASE_URL } from '@/env';
|
||||
import { COLLABORATION_BACKEND_BASE_URL, Y_PROVIDER_API_KEY } from '@/env';
|
||||
|
||||
export interface User {
|
||||
id: string;
|
||||
@@ -61,6 +61,7 @@ async function fetch<T>(
|
||||
headers: {
|
||||
cookie: requestHeaders['cookie'],
|
||||
origin: requestHeaders['origin'],
|
||||
'X-Y-Provider-Key': Y_PROVIDER_API_KEY,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user