diff --git a/src/public/neneks.json b/src/public/dictionary.json similarity index 100% rename from src/public/neneks.json rename to src/public/dictionary.json diff --git a/src/routes/index.js b/src/routes/index.js index 027c56f..468964c 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -1,15 +1,20 @@ const { Router } = require('express'); const router = Router(); -let jsonNenek = require('../public/neneks.json'); +const dictionary = require('../words.js'); +let jsonNenek = require('../public/dictionary.json'); // Get all diccionary -router.get("/dictionary", (req, res) => { +router.get("/", (req, res) => { res.render("dictionary", { title: 'Diccionario', words: jsonNenek }) }); +router.get("/dictionary", (req, res) => { + res.send(dictionary.allDictionary()) +}); + router.get("/es/:query", (req, res) => { var index = searchname(jsonNenek, req.params.query, "pal_esp"); if(index == -1) { @@ -41,12 +46,12 @@ var searchname = function(json, query, index){ for(var i = 0; i < json.length; i++) { if (json[i][index].indexOf(query)>-1){ const data = { - _id: json[i]['_id'], - num_pal: json[i]['num_pal'], + id: json[i]['_id'], + number_word: json[i]['num_pal'], query: query, - pal_tenek: json[i]['pal_tenek'], - pal_esp: json[i]['pal_esp'], - significado: json[i]['significado'] + tenek_word: json[i]['pal_tenek'], + spanish_word: json[i]['pal_esp'], + description: json[i]['significado'] } array.push(data) } diff --git a/src/words.js b/src/words.js new file mode 100644 index 0000000..6b4eafc --- /dev/null +++ b/src/words.js @@ -0,0 +1,7 @@ +let dictionary = require('./public/dictionary.json'); + +module.exports = { allDictionary } + +function allDictionary() { + return dictionary; +} \ No newline at end of file