Skip to content

Commit

Permalink
fix: fixed CORS problem
Browse files Browse the repository at this point in the history
  • Loading branch information
camarm-dev committed Jun 15, 2024
1 parent 7e6ae5a commit 5fb1571
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions app/src/functions/dictionnary.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import {getOfflineDictionaryStatus} from "@/functions/offline"
import {RemedeDatabase} from "@/functions/database"

const fetchOptions = {
mode: "no-cors"
} as RequestInit

function removeAccents(value: string) {
return value.normalize("NFD").replace(/\p{Diacritic}/gu, "").replaceAll("-", " ").replaceAll("'", " ")
}
Expand All @@ -14,39 +10,39 @@ async function useApi() {
}

async function getAutocompleteWithAPI(word: string) {
return await fetch(`https://api-remede.camarm.fr/autocomplete/${word}`, fetchOptions).then(resp => resp.json())
return await fetch(`https://api-remede.camarm.fr/autocomplete/${word}`).then(resp => resp.json())
}

async function getAutocompleteFromDatabase(word: string) {
return await database?.getAutocomplete(removeAccents(word)) as any[]
}

async function getSearchResultsWithAPI(query: string) {
return await fetch(`https://api-remede.camarm.fr/search/${query}`, fetchOptions).then(resp => resp.json())
return await fetch(`https://api-remede.camarm.fr/search/${query}`).then(resp => resp.json())
}

async function getSearchResultsFromDatabase(query: string) {
return await database?.search(removeAccents(query)) as any[]
}

async function getWordWithAPI(word: string) {
return await fetch(`https://api-remede.camarm.fr/word/${word}`, fetchOptions).then(resp => resp.json())
return await fetch(`https://api-remede.camarm.fr/word/${word}`).then(resp => resp.json())
}

async function getWordFromDatabase(word: string) {
return await database?.getWord(word) as any[]
}

async function getRandomWordWithAPI() {
return await fetch("https://api-remede.camarm.fr/random", fetchOptions).then(resp => resp.json())
return await fetch("https://api-remede.camarm.fr/random").then(resp => resp.json())
}

async function getRandomWordFromDatabase() {
return await database?.getRandomWord() as string
}

async function doesWordExistsWithAPI(word: string) {
return (await fetch(`https://api-remede.camarm.fr/word/${word}`, fetchOptions).then(resp => resp.json())).message != "Mot non trouvé"
return (await fetch(`https://api-remede.camarm.fr/word/${word}`).then(resp => resp.json())).message != "Mot non trouvé"
}

async function doesWordExistsWithDatabase(word: string) {
Expand Down Expand Up @@ -89,7 +85,7 @@ async function getRandomWord() {

async function getTodayWord() {
try {
return await fetch("https://api-remede.camarm.fr/word-of-day", fetchOptions).then(resp => resp.json())
return await fetch("https://api-remede.camarm.fr/word-of-day").then(resp => resp.json())
} catch (e) {
return ""
}
Expand Down

0 comments on commit 5fb1571

Please sign in to comment.