diff --git a/packages/services/cdn-worker/src/handler.ts b/packages/services/cdn-worker/src/handler.ts index 1197f872f..31ee32f6b 100644 --- a/packages/services/cdn-worker/src/handler.ts +++ b/packages/services/cdn-worker/src/handler.ts @@ -20,7 +20,13 @@ const artifactTypesHandlers = { /** * Returns SchemaArtifact or SchemaArtifact[], same way as it's stored in the storage */ - schema: (targetId: string, artifactType: string, rawValue: string) => new Response(rawValue, { status: 200 }), + schema: (targetId: string, artifactType: string, rawValue: string) => + new Response(rawValue, { + status: 200, + headers: { + 'Content-Type': 'application/json', + }, + }), /** * Returns Federation Supergraph, we store it as-is. */ diff --git a/packages/services/cdn-worker/tests/cdn.spec.ts b/packages/services/cdn-worker/tests/cdn.spec.ts index 933be1b9d..3f130bb38 100644 --- a/packages/services/cdn-worker/tests/cdn.spec.ts +++ b/packages/services/cdn-worker/tests/cdn.spec.ts @@ -35,6 +35,40 @@ describe('CDN Worker', () => { afterEach(clearWorkerEnv); + test('in /schema and /metadata the response should contain content-type: application/json header', async () => { + const SECRET = '123456'; + const targetId = 'fake-target-id'; + const map = new Map(); + map.set(`target:${targetId}:schema`, JSON.stringify({ sdl: `type Query { dummy: String }` })); + + mockWorkerEnv({ + HIVE_DATA: map, + KEY_DATA: SECRET, + }); + + const token = createToken(SECRET, targetId); + + const schemaRequest = new Request(`https://fake-worker.com/${targetId}/schema`, { + headers: { + 'x-hive-cdn-key': token, + }, + }); + + const schemaResponse = await handleRequest(schemaRequest, KeyValidators.Bcrypt); + expect(schemaResponse.status).toBe(200); + expect(schemaResponse.headers.get('content-type')).toBe('application/json'); + + const metadataRequest = new Request(`https://fake-worker.com/${targetId}/schema`, { + headers: { + 'x-hive-cdn-key': token, + }, + }); + + const metadataResponse = await handleRequest(metadataRequest, KeyValidators.Bcrypt); + expect(metadataResponse.status).toBe(200); + expect(metadataResponse.headers.get('content-type')).toBe('application/json'); + }); + describe('Basic parsing errors', () => { it('Should throw when target id is missing', async () => { mockWorkerEnv({ @@ -117,7 +151,7 @@ describe('CDN Worker', () => { expect(response.status).toBe(200); }); - it('Should throw on missmatch of token target and actual target', async () => { + it('Should throw on mismatch of token target and actual target', async () => { const SECRET = '123456'; mockWorkerEnv({