Skip to content

Commit

Permalink
fix(#1245170): [Schema] Force schema Content-Type header to prevent r…
Browse files Browse the repository at this point in the history
…eceving html response
  • Loading branch information
PierreGauthier committed Sep 27, 2024
1 parent fc67138 commit cfbba6d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/shared/src/services/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('Api service', () => {

describe('getApiUrl', () => {
it('should return the api URL', () => {
expect(getApiUrl()).toEqual('http://localhost/')
expect(getApiUrl()).toEqual('http://localhost')
expect(getApiUrl('/test')).toEqual('http://localhost/test')
expect(getApiUrl('test')).toEqual('http://localhost/test')
expect(getApiUrl('http://localhost/test')).toEqual(
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/services/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function isApiError<T extends object>(

export function getApiUrl(url = ''): string {
if (!url.startsWith('http')) {
if (!url.startsWith('/')) {
if (url.length && !url.startsWith('/')) {
url = `/${url}`
}
url = `${apiUrl}${url}`
Expand Down
8 changes: 6 additions & 2 deletions packages/shared/src/services/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ export async function fetchDocs(apiUrl: string): Promise<{
entrypoint: IExpandedEntrypoint
entrypointUrl: string
}> {
const { json: entrypoint, response } = await fetchJson<IEntrypoint>(apiUrl)
const { json: entrypoint, response } = await fetchJson<IEntrypoint>(apiUrl, {
headers: { 'Content-Type': 'application/ld+json' },
})
const docsUrl = getDocumentationUrlFromHeaders(response.headers, apiUrl)
const { json: docs } = await fetchJson<JsonLdDocument>(docsUrl)
const { json: docs } = await fetchJson<JsonLdDocument>(docsUrl, {
headers: { 'Content-Type': 'application/ld+json' },
})
const [expandedDoc, expandedEntrypoint] = await Promise.all([
jsonld.expand(docs, { base: docsUrl }),
jsonld.expand(entrypoint, { base: apiUrl }),
Expand Down

0 comments on commit cfbba6d

Please sign in to comment.