diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000000000000000000000000000000000000..f494c12865a64aa17e94328cfc9b99bcc10e3c8f --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +node_modules +npm-debug.log +mysql.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..88d63f878567c3697c49ec3ae1b684ebbeee945a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +FROM node:12 + +# Create app directory +WORKDIR /usr/src/app + +# Install app dependencies +# A wildcard is used to ensure both package.json AND package-lock.json are copied +# where available (npm@5+) +COPY package*.json ./ + +RUN npm install +# If you are building your code for production +# RUN npm ci --only=production + +# Bundle app source +COPY . . + +EXPOSE 8000 +CMD [ "node", "index.js" ] diff --git a/HelperFunctions.js b/HelperFunctions.js index 3ffae7abbe2d855f33cf914ef61e665e65a8d14b..66dc643866284db5e2a0e8a03a6c092fcc3c07a5 100644 --- a/HelperFunctions.js +++ b/HelperFunctions.js @@ -4,6 +4,7 @@ const conjunctions = [" ja ", " sekä ", " että ", " eli ", " tai ", " joko ", const beVerbs = [" olen ", " olet ", " on ", " olemme ", " olette ", " ovat ", " ollaan ", " olla "] counter = 0 +// Shiftaa kaikki lauseet ja palauttaa listan listoja, joissa alilista on aina yhden lauseen kaikki 29 shiftaus vaihtoehtoa async function getAllPossibilities(data){ let text = data.toString().toLowerCase() let arrayOfPossibilities = [] @@ -24,6 +25,7 @@ async function getAllPossibilities(data){ return arrayOfPossibilities } +// Apufunktio lauseiden shiftaamiseen async function shiftLeft(text, shiftAmount){ let uusi = ""; for(let i=0; i<text.length; i++){ @@ -38,6 +40,7 @@ async function shiftLeft(text, shiftAmount){ return uusi; } +// Varmistaa, että shiftaus ei mene yli aakkoston async function shiftHelper(charLoc, shiftAmount){ let result = charLoc - shiftAmount; //console.log("result: "+result); @@ -50,6 +53,7 @@ async function shiftHelper(charLoc, shiftAmount){ } } +// Funktio, jolla tarkistetaan onko lause suomea vai jotakin muuta async function onkoSuomea(text){ /*let previousChar = '0' let previousChar2 = '0' @@ -66,7 +70,9 @@ async function onkoSuomea(text){ previousChar = currentChar; } else{ - if(await check3Consonants(currentChar, previousChar, previousChar2)){ + let totuus = await check3Consonants(currentChar, previousChar, previousChar2) + console.log("Mitä funktio palauttaa: "+totuus) + if(totuus){ console.log("KOLME peräkkäistä konsonanttia "+ currentChar,previousChar, previousChar2) return false; } @@ -74,6 +80,7 @@ async function onkoSuomea(text){ previousChar = currentChar; } }*/ + //comment if(await checkConjunctions(text) || await checkBeVerbs(text)){ return true } @@ -102,7 +109,9 @@ async function checkBeVerbs(text){ async function check3Consonants( a, b, c){ //console.log("3 consonants") //console.log(consonants.includes(a, b, c)) - if(await consonants.includes(a, b, c)){ + let totuus = await consonants.includes(a && b && c) + console.log("löytyykö kolme konsonanttia: "+totuus) + if(totuus){ return true; } else{ diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000000000000000000000000000000000000..bbea762736a8335cbbdbbacb4b4a1579da861cc3 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,20 @@ +version: '3' + +services: + + mysql-development: + image: mysql + expose: + - '3306' + ports: + - '3306:3306' + environment: + MYSQL_ROOT_PASSWORD: 'pass' + MYSQL_DATABASE: 'db' + MYSQL_USER: 'user' + MYSQL_PASSWORD: 'pass' + + node-backend: + build: . + ports: + - "8000:8000" diff --git a/index.js b/index.js index f85d96e14ba090508d4d3f6b1afc79fb28f0034f..b4cb1059df44bb6fd62b1f9e8870c2505d5cccd0 100644 --- a/index.js +++ b/index.js @@ -9,11 +9,11 @@ app.use(cors()) let token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJidWxsc2hpdCI6ImJ1bGxzaGl0IiwiaWF0IjoxNTcxMTQ0ODc3fQ.2hTbepbeUpxDGSATKybnKpxOcmLEbt2oaRDu8B129xs" let data let dataArray -let testArray = "Jeejee moimoi kaikki ja tässä on testi lause." +let testArray = ["Jeejee moimoi kaikki ja tässä on testi lause."] let kaikki = [] - +// Haetaan lauseet palvelimelta async function getData() { const request = await axios.get('https://koodihaaste-api.solidabis.com/bullshit', { headers: { @@ -26,6 +26,7 @@ async function getData() { return data } +// Käsitellään data haluttuun muotoon async function modifyData(){ if(dataArray == undefined){ await getData() @@ -37,6 +38,7 @@ async function modifyData(){ //console.log(messageArray[0]) try{ //Kaikki sisältää listan listoja, joissa alilistana on yksi lause sen kaikkine caesar salaus vaihtoehtoineen + //Jos halutaan testata, niin messageArray --> testArray for(let message of messageArray){ let list = await HelperFunctions.getAllPossibilities(message) let truth = false