Move CORS support to hooks.
This commit is contained in:
parent
813550a6a0
commit
87df843b82
22 changed files with 28 additions and 44 deletions
|
@ -9,6 +9,7 @@ export const getSession: GetSession = async () => {
|
|||
}
|
||||
|
||||
export const handle: Handle = async ({ event, resolve }) => {
|
||||
// Add CORS support.
|
||||
const { request } = event
|
||||
if (request.method === "OPTIONS") {
|
||||
const headers: { [name: string]: string } = {
|
||||
|
@ -32,5 +33,9 @@ export const handle: Handle = async ({ event, resolve }) => {
|
|||
return new Response(null, { status: 204, headers })
|
||||
}
|
||||
|
||||
return await resolve(event)
|
||||
const response = await resolve(event)
|
||||
if (response.headers.get("Content-Type")?.startsWith("application/json")) {
|
||||
response.headers.set("Access-Control-Allow-Origin", "*")
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
|
|
@ -13,10 +13,9 @@ export const GET: RequestHandler = async ({ params }) => {
|
|||
).map(({ data }) => data)[0]
|
||||
|
||||
if (article === undefined) {
|
||||
return { headers: { "Access-Control-Allow-Origin": "*" }, status: 404 }
|
||||
return { status: 404 }
|
||||
}
|
||||
return {
|
||||
headers: { "Access-Control-Allow-Origin": "*" },
|
||||
body: { article: article as unknown as JSONObject },
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ export const GET: RequestHandler = async ({ url }) => {
|
|||
)
|
||||
return {
|
||||
// status: 400,
|
||||
headers: { "Access-Control-Allow-Origin": "*" },
|
||||
|
||||
body: {
|
||||
error: {
|
||||
query: queryError as unknown as JSONObject,
|
||||
|
@ -66,7 +66,6 @@ export const GET: RequestHandler = async ({ url }) => {
|
|||
`
|
||||
).map(({ data }) => data)
|
||||
return {
|
||||
headers: { "Access-Control-Allow-Origin": "*" },
|
||||
body: { article: articles as unknown as JSONObject[] },
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,10 +13,9 @@ export const GET: RequestHandler = async ({ params }) => {
|
|||
).map(({ data }) => data)[0]
|
||||
|
||||
if (dossierLegislatif === undefined) {
|
||||
return { headers: { "Access-Control-Allow-Origin": "*" }, status: 404 }
|
||||
return { status: 404 }
|
||||
}
|
||||
return {
|
||||
headers: { "Access-Control-Allow-Origin": "*" },
|
||||
body: { dossier_legislatif: dossierLegislatif as unknown as JSONObject },
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ export const GET: RequestHandler = async ({ url }) => {
|
|||
)
|
||||
return {
|
||||
// status: 400,
|
||||
headers: { "Access-Control-Allow-Origin": "*" },
|
||||
|
||||
body: {
|
||||
error: {
|
||||
query: queryError as unknown as JSONObject,
|
||||
|
@ -66,7 +66,6 @@ export const GET: RequestHandler = async ({ url }) => {
|
|||
`
|
||||
).map(({ data }) => data)
|
||||
return {
|
||||
headers: { "Access-Control-Allow-Origin": "*" },
|
||||
body: {
|
||||
dossier_legislatif: dossiersLegislatifs as unknown as JSONObject[],
|
||||
},
|
||||
|
|
|
@ -13,10 +13,9 @@ export const GET: RequestHandler = async ({ params }) => {
|
|||
)[0]
|
||||
|
||||
if (idWrapper === undefined) {
|
||||
return { headers: { "Access-Control-Allow-Origin": "*" }, status: 404 }
|
||||
return { status: 404 }
|
||||
}
|
||||
return {
|
||||
headers: { "Access-Control-Allow-Origin": "*" },
|
||||
body: { id: idWrapper as unknown as JSONObject },
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ export const GET: RequestHandler = async ({ url }) => {
|
|||
)
|
||||
return {
|
||||
// status: 400,
|
||||
headers: { "Access-Control-Allow-Origin": "*" },
|
||||
|
||||
body: {
|
||||
error: {
|
||||
query: queryError as unknown as JSONObject,
|
||||
|
@ -64,7 +64,6 @@ export const GET: RequestHandler = async ({ url }) => {
|
|||
LIMIT ${limit}
|
||||
`
|
||||
return {
|
||||
headers: { "Access-Control-Allow-Origin": "*" },
|
||||
body: { id: idsWrapper as unknown as JSONObject[] },
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,10 +13,9 @@ export const GET: RequestHandler = async ({ params }) => {
|
|||
).map(({ data }) => data)[0]
|
||||
|
||||
if (idcc === undefined) {
|
||||
return { headers: { "Access-Control-Allow-Origin": "*" }, status: 404 }
|
||||
return { status: 404 }
|
||||
}
|
||||
return {
|
||||
headers: { "Access-Control-Allow-Origin": "*" },
|
||||
body: { idcc: idcc as unknown as JSONObject },
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ export const GET: RequestHandler = async ({ url }) => {
|
|||
)
|
||||
return {
|
||||
// status: 400,
|
||||
headers: { "Access-Control-Allow-Origin": "*" },
|
||||
|
||||
body: {
|
||||
error: {
|
||||
query: queryError as unknown as JSONObject,
|
||||
|
@ -66,7 +66,6 @@ export const GET: RequestHandler = async ({ url }) => {
|
|||
`
|
||||
).map(({ data }) => data)
|
||||
return {
|
||||
headers: { "Access-Control-Allow-Origin": "*" },
|
||||
body: { idcc: idccArray as unknown as JSONObject[] },
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,10 +13,9 @@ export const GET: RequestHandler = async ({ params }) => {
|
|||
).map(({ data }) => data)[0]
|
||||
|
||||
if (jo === undefined) {
|
||||
return { headers: { "Access-Control-Allow-Origin": "*" }, status: 404 }
|
||||
return { status: 404 }
|
||||
}
|
||||
return {
|
||||
headers: { "Access-Control-Allow-Origin": "*" },
|
||||
body: { jo: jo as unknown as JSONObject },
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ export const GET: RequestHandler = async ({ url }) => {
|
|||
)
|
||||
return {
|
||||
// status: 400,
|
||||
headers: { "Access-Control-Allow-Origin": "*" },
|
||||
|
||||
body: {
|
||||
error: {
|
||||
query: queryError as unknown as JSONObject,
|
||||
|
@ -66,7 +66,6 @@ export const GET: RequestHandler = async ({ url }) => {
|
|||
`
|
||||
).map(({ data }) => data)
|
||||
return {
|
||||
headers: { "Access-Control-Allow-Origin": "*" },
|
||||
body: { jo: jos as unknown as JSONObject[] },
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ export const GET: RequestHandler = async ({ url }) => {
|
|||
)
|
||||
return {
|
||||
// status: 400,
|
||||
headers: { "Access-Control-Allow-Origin": "*" },
|
||||
|
||||
body: {
|
||||
error: {
|
||||
query: queryError as unknown as JSONObject,
|
||||
|
@ -74,10 +74,9 @@ export const GET: RequestHandler = async ({ url }) => {
|
|||
`
|
||||
).map(({ data }) => data)
|
||||
return {
|
||||
headers: { "Access-Control-Allow-Origin": "*" },
|
||||
body: { articles: articles as unknown as JSONObject[], q },
|
||||
}
|
||||
}
|
||||
}
|
||||
return { headers: { "Access-Control-Allow-Origin": "*" }, body: {} }
|
||||
return { body: {} }
|
||||
}
|
||||
|
|
|
@ -13,10 +13,9 @@ export const GET: RequestHandler = async ({ params }) => {
|
|||
).map(({ data }) => data)[0]
|
||||
|
||||
if (sectionTa === undefined) {
|
||||
return { headers: { "Access-Control-Allow-Origin": "*" }, status: 404 }
|
||||
return { status: 404 }
|
||||
}
|
||||
return {
|
||||
headers: { "Access-Control-Allow-Origin": "*" },
|
||||
body: { section_ta: sectionTa as unknown as JSONObject },
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ export const GET: RequestHandler = async ({ url }) => {
|
|||
)
|
||||
return {
|
||||
// status: 400,
|
||||
headers: { "Access-Control-Allow-Origin": "*" },
|
||||
|
||||
body: {
|
||||
error: {
|
||||
query: queryError as unknown as JSONObject,
|
||||
|
@ -66,7 +66,6 @@ export const GET: RequestHandler = async ({ url }) => {
|
|||
`
|
||||
).map(({ data }) => data)
|
||||
return {
|
||||
headers: { "Access-Control-Allow-Origin": "*" },
|
||||
body: { section_ta: sectionTaArray as unknown as JSONObject[] },
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,10 +13,9 @@ export const GET: RequestHandler = async ({ params }) => {
|
|||
).map(({ data }) => data)[0]
|
||||
|
||||
if (texteVersion === undefined) {
|
||||
return { headers: { "Access-Control-Allow-Origin": "*" }, status: 404 }
|
||||
return { status: 404 }
|
||||
}
|
||||
return {
|
||||
headers: { "Access-Control-Allow-Origin": "*" },
|
||||
body: { texte_version: texteVersion as unknown as JSONObject },
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ export const GET: RequestHandler = async ({ url }) => {
|
|||
)
|
||||
return {
|
||||
// status: 400,
|
||||
headers: { "Access-Control-Allow-Origin": "*" },
|
||||
|
||||
body: {
|
||||
error: {
|
||||
query: queryError as unknown as JSONObject,
|
||||
|
@ -66,7 +66,6 @@ export const GET: RequestHandler = async ({ url }) => {
|
|||
`
|
||||
).map(({ data }) => data)
|
||||
return {
|
||||
headers: { "Access-Control-Allow-Origin": "*" },
|
||||
body: { texte_version: texteVersionArray as unknown as JSONObject[] },
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,10 +13,9 @@ export const GET: RequestHandler = async ({ params }) => {
|
|||
).map(({ data }) => data)[0]
|
||||
|
||||
if (textekali === undefined) {
|
||||
return { headers: { "Access-Control-Allow-Origin": "*" }, status: 404 }
|
||||
return { status: 404 }
|
||||
}
|
||||
return {
|
||||
headers: { "Access-Control-Allow-Origin": "*" },
|
||||
body: { textekali: textekali as unknown as JSONObject },
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ export const GET: RequestHandler = async ({ url }) => {
|
|||
)
|
||||
return {
|
||||
// status: 400,
|
||||
headers: { "Access-Control-Allow-Origin": "*" },
|
||||
|
||||
body: {
|
||||
error: {
|
||||
query: queryError as unknown as JSONObject,
|
||||
|
@ -66,7 +66,6 @@ export const GET: RequestHandler = async ({ url }) => {
|
|||
`
|
||||
).map(({ data }) => data)
|
||||
return {
|
||||
headers: { "Access-Control-Allow-Origin": "*" },
|
||||
body: { textekali: textekaliArray as unknown as JSONObject[] },
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,10 +13,9 @@ export const GET: RequestHandler = async ({ params }) => {
|
|||
).map(({ data }) => data)[0]
|
||||
|
||||
if (textelr === undefined) {
|
||||
return { headers: { "Access-Control-Allow-Origin": "*" }, status: 404 }
|
||||
return { status: 404 }
|
||||
}
|
||||
return {
|
||||
headers: { "Access-Control-Allow-Origin": "*" },
|
||||
body: { textelr: textelr as unknown as JSONObject },
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ export const GET: RequestHandler = async ({ url }) => {
|
|||
)
|
||||
return {
|
||||
// status: 400,
|
||||
headers: { "Access-Control-Allow-Origin": "*" },
|
||||
|
||||
body: {
|
||||
error: {
|
||||
query: queryError as unknown as JSONObject,
|
||||
|
@ -66,7 +66,6 @@ export const GET: RequestHandler = async ({ url }) => {
|
|||
`
|
||||
).map(({ data }) => data)
|
||||
return {
|
||||
headers: { "Access-Control-Allow-Origin": "*" },
|
||||
body: { textelr: textelrArray as unknown as JSONObject[] },
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,10 +13,9 @@ export const GET: RequestHandler = async ({ params }) => {
|
|||
)[0]
|
||||
|
||||
if (versionsWrapper === undefined) {
|
||||
return { headers: { "Access-Control-Allow-Origin": "*" }, status: 404 }
|
||||
return { status: 404 }
|
||||
}
|
||||
return {
|
||||
headers: { "Access-Control-Allow-Origin": "*" },
|
||||
body: { versions: versionsWrapper as unknown as JSONObject },
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ export const GET: RequestHandler = async ({ url }) => {
|
|||
)
|
||||
return {
|
||||
// status: 400,
|
||||
headers: { "Access-Control-Allow-Origin": "*" },
|
||||
|
||||
body: {
|
||||
error: {
|
||||
query: queryError as unknown as JSONObject,
|
||||
|
@ -64,7 +64,6 @@ export const GET: RequestHandler = async ({ url }) => {
|
|||
LIMIT ${limit}
|
||||
`
|
||||
return {
|
||||
headers: { "Access-Control-Allow-Origin": "*" },
|
||||
body: { versions: versionsWrapper as unknown as JSONObject[] },
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue