Add Access-Control-Allow-Origin headers to JSON responses.

This commit is contained in:
Emmanuel 2022-08-11 22:07:08 +02:00
parent d7c75afa4c
commit 7602ac2852
9 changed files with 46 additions and 14 deletions

View file

@ -13,7 +13,10 @@ export const GET: RequestHandler = async ({ params, url }) => {
).map(({ data }) => data)[0] ).map(({ data }) => data)[0]
if (article === undefined) { if (article === undefined) {
return { status: 404 } return { headers: { "Access-Control-Allow-Origin": "*" }, status: 404 }
}
return {
headers: { "Access-Control-Allow-Origin": "*" },
body: { article: article as unknown as JSONObject },
} }
return { body: { article: article as unknown as JSONObject } }
} }

View file

@ -48,6 +48,7 @@ export const GET: RequestHandler = async ({ url }) => {
) )
return { return {
// status: 400, // status: 400,
headers: { "Access-Control-Allow-Origin": "*" },
body: { body: {
error: { error: {
query: queryError as unknown as JSONObject, query: queryError as unknown as JSONObject,
@ -64,5 +65,8 @@ export const GET: RequestHandler = async ({ url }) => {
LIMIT ${limit} LIMIT ${limit}
` `
).map(({ data }) => data) ).map(({ data }) => data)
return { body: { articles: articles as unknown as JSONObject[] } } return {
headers: { "Access-Control-Allow-Origin": "*" },
body: { articles: articles as unknown as JSONObject[] },
}
} }

View file

@ -48,6 +48,7 @@ export const GET: RequestHandler = async ({ url }) => {
) )
return { return {
// status: 400, // status: 400,
headers: { "Access-Control-Allow-Origin": "*" },
body: { body: {
error: { error: {
query: queryError as unknown as JSONObject, query: queryError as unknown as JSONObject,
@ -72,8 +73,11 @@ export const GET: RequestHandler = async ({ url }) => {
WHERE id = ${articleId} WHERE id = ${articleId}
` `
).map(({ data }) => data) ).map(({ data }) => data)
return { body: { articles: articles as unknown as JSONObject[], q } } return {
headers: { "Access-Control-Allow-Origin": "*" },
body: { articles: articles as unknown as JSONObject[], q },
}
} }
} }
return { body: {} } return { headers: { "Access-Control-Allow-Origin": "*" }, body: {} }
} }

View file

@ -13,7 +13,10 @@ export const GET: RequestHandler = async ({ params, url }) => {
).map(({ data }) => data)[0] ).map(({ data }) => data)[0]
if (section === undefined) { if (section === undefined) {
return { status: 404 } return { headers: { "Access-Control-Allow-Origin": "*" }, status: 404 }
}
return {
headers: { "Access-Control-Allow-Origin": "*" },
body: { section: section as unknown as JSONObject },
} }
return { body: { section: section as unknown as JSONObject } }
} }

View file

@ -48,6 +48,7 @@ export const GET: RequestHandler = async ({ url }) => {
) )
return { return {
// status: 400, // status: 400,
headers: { "Access-Control-Allow-Origin": "*" },
body: { body: {
error: { error: {
query: queryError as unknown as JSONObject, query: queryError as unknown as JSONObject,
@ -64,5 +65,8 @@ export const GET: RequestHandler = async ({ url }) => {
LIMIT ${limit} LIMIT ${limit}
` `
).map(({ data }) => data) ).map(({ data }) => data)
return { body: { sections: sections as unknown as JSONObject[] } } return {
headers: { "Access-Control-Allow-Origin": "*" },
body: { sections: sections as unknown as JSONObject[] },
}
} }

View file

@ -13,7 +13,10 @@ export const GET: RequestHandler = async ({ params, url }) => {
).map(({ data }) => data)[0] ).map(({ data }) => data)[0]
if (struct === undefined) { if (struct === undefined) {
return { status: 404 } return { headers: { "Access-Control-Allow-Origin": "*" }, status: 404 }
}
return {
headers: { "Access-Control-Allow-Origin": "*" },
body: { struct: struct as unknown as JSONObject },
} }
return { body: { struct: struct as unknown as JSONObject } }
} }

View file

@ -48,6 +48,7 @@ export const GET: RequestHandler = async ({ url }) => {
) )
return { return {
// status: 400, // status: 400,
headers: { "Access-Control-Allow-Origin": "*" },
body: { body: {
error: { error: {
query: queryError as unknown as JSONObject, query: queryError as unknown as JSONObject,
@ -64,5 +65,8 @@ export const GET: RequestHandler = async ({ url }) => {
LIMIT ${limit} LIMIT ${limit}
` `
).map(({ data }) => data) ).map(({ data }) => data)
return { body: { structs: structs as unknown as JSONObject[] } } return {
headers: { "Access-Control-Allow-Origin": "*" },
body: { structs: structs as unknown as JSONObject[] },
}
} }

View file

@ -13,7 +13,10 @@ export const GET: RequestHandler = async ({ params, url }) => {
).map(({ data }) => data)[0] ).map(({ data }) => data)[0]
if (texte === undefined) { if (texte === undefined) {
return { status: 404 } return { headers: { "Access-Control-Allow-Origin": "*" }, status: 404 }
}
return {
headers: { "Access-Control-Allow-Origin": "*" },
body: { texte: texte as unknown as JSONObject },
} }
return { body: { texte: texte as unknown as JSONObject } }
} }

View file

@ -48,6 +48,7 @@ export const GET: RequestHandler = async ({ url }) => {
) )
return { return {
// status: 400, // status: 400,
headers: { "Access-Control-Allow-Origin": "*" },
body: { body: {
error: { error: {
query: queryError as unknown as JSONObject, query: queryError as unknown as JSONObject,
@ -64,5 +65,8 @@ export const GET: RequestHandler = async ({ url }) => {
LIMIT ${limit} LIMIT ${limit}
` `
).map(({ data }) => data) ).map(({ data }) => data)
return { body: { textes: textes as unknown as JSONObject[] } } return {
headers: { "Access-Control-Allow-Origin": "*" },
body: { textes: textes as unknown as JSONObject[] },
}
} }