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 }) => {
|
export const handle: Handle = async ({ event, resolve }) => {
|
||||||
|
// Add CORS support.
|
||||||
const { request } = event
|
const { request } = event
|
||||||
if (request.method === "OPTIONS") {
|
if (request.method === "OPTIONS") {
|
||||||
const headers: { [name: string]: string } = {
|
const headers: { [name: string]: string } = {
|
||||||
|
@ -32,5 +33,9 @@ export const handle: Handle = async ({ event, resolve }) => {
|
||||||
return new Response(null, { status: 204, headers })
|
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]
|
).map(({ data }) => data)[0]
|
||||||
|
|
||||||
if (article === undefined) {
|
if (article === undefined) {
|
||||||
return { headers: { "Access-Control-Allow-Origin": "*" }, status: 404 }
|
return { status: 404 }
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
headers: { "Access-Control-Allow-Origin": "*" },
|
|
||||||
body: { article: article as unknown as JSONObject },
|
body: { article: article as unknown as JSONObject },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +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,
|
||||||
|
@ -66,7 +66,6 @@ export const GET: RequestHandler = async ({ url }) => {
|
||||||
`
|
`
|
||||||
).map(({ data }) => data)
|
).map(({ data }) => data)
|
||||||
return {
|
return {
|
||||||
headers: { "Access-Control-Allow-Origin": "*" },
|
|
||||||
body: { article: articles as unknown as JSONObject[] },
|
body: { article: articles as unknown as JSONObject[] },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,10 +13,9 @@ export const GET: RequestHandler = async ({ params }) => {
|
||||||
).map(({ data }) => data)[0]
|
).map(({ data }) => data)[0]
|
||||||
|
|
||||||
if (dossierLegislatif === undefined) {
|
if (dossierLegislatif === undefined) {
|
||||||
return { headers: { "Access-Control-Allow-Origin": "*" }, status: 404 }
|
return { status: 404 }
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
headers: { "Access-Control-Allow-Origin": "*" },
|
|
||||||
body: { dossier_legislatif: dossierLegislatif as unknown as JSONObject },
|
body: { dossier_legislatif: dossierLegislatif as unknown as JSONObject },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +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,
|
||||||
|
@ -66,7 +66,6 @@ export const GET: RequestHandler = async ({ url }) => {
|
||||||
`
|
`
|
||||||
).map(({ data }) => data)
|
).map(({ data }) => data)
|
||||||
return {
|
return {
|
||||||
headers: { "Access-Control-Allow-Origin": "*" },
|
|
||||||
body: {
|
body: {
|
||||||
dossier_legislatif: dossiersLegislatifs as unknown as JSONObject[],
|
dossier_legislatif: dossiersLegislatifs as unknown as JSONObject[],
|
||||||
},
|
},
|
||||||
|
|
|
@ -13,10 +13,9 @@ export const GET: RequestHandler = async ({ params }) => {
|
||||||
)[0]
|
)[0]
|
||||||
|
|
||||||
if (idWrapper === undefined) {
|
if (idWrapper === undefined) {
|
||||||
return { headers: { "Access-Control-Allow-Origin": "*" }, status: 404 }
|
return { status: 404 }
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
headers: { "Access-Control-Allow-Origin": "*" },
|
|
||||||
body: { id: idWrapper as unknown as JSONObject },
|
body: { id: idWrapper as unknown as JSONObject },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +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,7 +64,6 @@ export const GET: RequestHandler = async ({ url }) => {
|
||||||
LIMIT ${limit}
|
LIMIT ${limit}
|
||||||
`
|
`
|
||||||
return {
|
return {
|
||||||
headers: { "Access-Control-Allow-Origin": "*" },
|
|
||||||
body: { id: idsWrapper as unknown as JSONObject[] },
|
body: { id: idsWrapper as unknown as JSONObject[] },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,10 +13,9 @@ export const GET: RequestHandler = async ({ params }) => {
|
||||||
).map(({ data }) => data)[0]
|
).map(({ data }) => data)[0]
|
||||||
|
|
||||||
if (idcc === undefined) {
|
if (idcc === undefined) {
|
||||||
return { headers: { "Access-Control-Allow-Origin": "*" }, status: 404 }
|
return { status: 404 }
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
headers: { "Access-Control-Allow-Origin": "*" },
|
|
||||||
body: { idcc: idcc as unknown as JSONObject },
|
body: { idcc: idcc as unknown as JSONObject },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +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,
|
||||||
|
@ -66,7 +66,6 @@ export const GET: RequestHandler = async ({ url }) => {
|
||||||
`
|
`
|
||||||
).map(({ data }) => data)
|
).map(({ data }) => data)
|
||||||
return {
|
return {
|
||||||
headers: { "Access-Control-Allow-Origin": "*" },
|
|
||||||
body: { idcc: idccArray as unknown as JSONObject[] },
|
body: { idcc: idccArray as unknown as JSONObject[] },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,10 +13,9 @@ export const GET: RequestHandler = async ({ params }) => {
|
||||||
).map(({ data }) => data)[0]
|
).map(({ data }) => data)[0]
|
||||||
|
|
||||||
if (jo === undefined) {
|
if (jo === undefined) {
|
||||||
return { headers: { "Access-Control-Allow-Origin": "*" }, status: 404 }
|
return { status: 404 }
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
headers: { "Access-Control-Allow-Origin": "*" },
|
|
||||||
body: { jo: jo as unknown as JSONObject },
|
body: { jo: jo as unknown as JSONObject },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +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,
|
||||||
|
@ -66,7 +66,6 @@ export const GET: RequestHandler = async ({ url }) => {
|
||||||
`
|
`
|
||||||
).map(({ data }) => data)
|
).map(({ data }) => data)
|
||||||
return {
|
return {
|
||||||
headers: { "Access-Control-Allow-Origin": "*" },
|
|
||||||
body: { jo: jos as unknown as JSONObject[] },
|
body: { jo: jos as unknown as JSONObject[] },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +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,
|
||||||
|
@ -74,10 +74,9 @@ export const GET: RequestHandler = async ({ url }) => {
|
||||||
`
|
`
|
||||||
).map(({ data }) => data)
|
).map(({ data }) => data)
|
||||||
return {
|
return {
|
||||||
headers: { "Access-Control-Allow-Origin": "*" },
|
|
||||||
body: { articles: articles as unknown as JSONObject[], q },
|
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]
|
).map(({ data }) => data)[0]
|
||||||
|
|
||||||
if (sectionTa === undefined) {
|
if (sectionTa === undefined) {
|
||||||
return { headers: { "Access-Control-Allow-Origin": "*" }, status: 404 }
|
return { status: 404 }
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
headers: { "Access-Control-Allow-Origin": "*" },
|
|
||||||
body: { section_ta: sectionTa as unknown as JSONObject },
|
body: { section_ta: sectionTa as unknown as JSONObject },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +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,
|
||||||
|
@ -66,7 +66,6 @@ export const GET: RequestHandler = async ({ url }) => {
|
||||||
`
|
`
|
||||||
).map(({ data }) => data)
|
).map(({ data }) => data)
|
||||||
return {
|
return {
|
||||||
headers: { "Access-Control-Allow-Origin": "*" },
|
|
||||||
body: { section_ta: sectionTaArray as unknown as JSONObject[] },
|
body: { section_ta: sectionTaArray as unknown as JSONObject[] },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,10 +13,9 @@ export const GET: RequestHandler = async ({ params }) => {
|
||||||
).map(({ data }) => data)[0]
|
).map(({ data }) => data)[0]
|
||||||
|
|
||||||
if (texteVersion === undefined) {
|
if (texteVersion === undefined) {
|
||||||
return { headers: { "Access-Control-Allow-Origin": "*" }, status: 404 }
|
return { status: 404 }
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
headers: { "Access-Control-Allow-Origin": "*" },
|
|
||||||
body: { texte_version: texteVersion as unknown as JSONObject },
|
body: { texte_version: texteVersion as unknown as JSONObject },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +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,
|
||||||
|
@ -66,7 +66,6 @@ export const GET: RequestHandler = async ({ url }) => {
|
||||||
`
|
`
|
||||||
).map(({ data }) => data)
|
).map(({ data }) => data)
|
||||||
return {
|
return {
|
||||||
headers: { "Access-Control-Allow-Origin": "*" },
|
|
||||||
body: { texte_version: texteVersionArray as unknown as JSONObject[] },
|
body: { texte_version: texteVersionArray as unknown as JSONObject[] },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,10 +13,9 @@ export const GET: RequestHandler = async ({ params }) => {
|
||||||
).map(({ data }) => data)[0]
|
).map(({ data }) => data)[0]
|
||||||
|
|
||||||
if (textekali === undefined) {
|
if (textekali === undefined) {
|
||||||
return { headers: { "Access-Control-Allow-Origin": "*" }, status: 404 }
|
return { status: 404 }
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
headers: { "Access-Control-Allow-Origin": "*" },
|
|
||||||
body: { textekali: textekali as unknown as JSONObject },
|
body: { textekali: textekali as unknown as JSONObject },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +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,
|
||||||
|
@ -66,7 +66,6 @@ export const GET: RequestHandler = async ({ url }) => {
|
||||||
`
|
`
|
||||||
).map(({ data }) => data)
|
).map(({ data }) => data)
|
||||||
return {
|
return {
|
||||||
headers: { "Access-Control-Allow-Origin": "*" },
|
|
||||||
body: { textekali: textekaliArray as unknown as JSONObject[] },
|
body: { textekali: textekaliArray as unknown as JSONObject[] },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,10 +13,9 @@ export const GET: RequestHandler = async ({ params }) => {
|
||||||
).map(({ data }) => data)[0]
|
).map(({ data }) => data)[0]
|
||||||
|
|
||||||
if (textelr === undefined) {
|
if (textelr === undefined) {
|
||||||
return { headers: { "Access-Control-Allow-Origin": "*" }, status: 404 }
|
return { status: 404 }
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
headers: { "Access-Control-Allow-Origin": "*" },
|
|
||||||
body: { textelr: textelr as unknown as JSONObject },
|
body: { textelr: textelr as unknown as JSONObject },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +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,
|
||||||
|
@ -66,7 +66,6 @@ export const GET: RequestHandler = async ({ url }) => {
|
||||||
`
|
`
|
||||||
).map(({ data }) => data)
|
).map(({ data }) => data)
|
||||||
return {
|
return {
|
||||||
headers: { "Access-Control-Allow-Origin": "*" },
|
|
||||||
body: { textelr: textelrArray as unknown as JSONObject[] },
|
body: { textelr: textelrArray as unknown as JSONObject[] },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,10 +13,9 @@ export const GET: RequestHandler = async ({ params }) => {
|
||||||
)[0]
|
)[0]
|
||||||
|
|
||||||
if (versionsWrapper === undefined) {
|
if (versionsWrapper === undefined) {
|
||||||
return { headers: { "Access-Control-Allow-Origin": "*" }, status: 404 }
|
return { status: 404 }
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
headers: { "Access-Control-Allow-Origin": "*" },
|
|
||||||
body: { versions: versionsWrapper as unknown as JSONObject },
|
body: { versions: versionsWrapper as unknown as JSONObject },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +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,7 +64,6 @@ export const GET: RequestHandler = async ({ url }) => {
|
||||||
LIMIT ${limit}
|
LIMIT ${limit}
|
||||||
`
|
`
|
||||||
return {
|
return {
|
||||||
headers: { "Access-Control-Allow-Origin": "*" },
|
|
||||||
body: { versions: versionsWrapper as unknown as JSONObject[] },
|
body: { versions: versionsWrapper as unknown as JSONObject[] },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue