diff options
Diffstat (limited to 'src/internal-server/app/Controllers/Http/RecipeController.js')
-rw-r--r-- | src/internal-server/app/Controllers/Http/RecipeController.js | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/internal-server/app/Controllers/Http/RecipeController.js b/src/internal-server/app/Controllers/Http/RecipeController.js index 8a6b4f684..1a7595a9d 100644 --- a/src/internal-server/app/Controllers/Http/RecipeController.js +++ b/src/internal-server/app/Controllers/Http/RecipeController.js | |||
@@ -6,8 +6,11 @@ const { | |||
6 | const Env = use('Env'); | 6 | const Env = use('Env'); |
7 | 7 | ||
8 | const fetch = require('node-fetch'); | 8 | const fetch = require('node-fetch'); |
9 | const debug = require('debug')('Ferdi:internalServer:RecipeController'); | ||
10 | const { LIVE_FERDI_API } = require('../../../../config'); | ||
11 | const { API_VERSION } = require('../../../../environment'); | ||
9 | 12 | ||
10 | const RECIPES_URL = 'https://api.getferdi.com/v1/recipes'; | 13 | const RECIPES_URL = `${LIVE_FERDI_API}/${API_VERSION}/recipes`; |
11 | 14 | ||
12 | class RecipeController { | 15 | class RecipeController { |
13 | // List official and custom recipes | 16 | // List official and custom recipes |
@@ -64,6 +67,9 @@ class RecipeController { | |||
64 | if (Env.get('CONNECT_WITH_FRANZ') == 'true') { // eslint-disable-line eqeqeq | 67 | if (Env.get('CONNECT_WITH_FRANZ') == 'true') { // eslint-disable-line eqeqeq |
65 | remoteResults = JSON.parse(await (await fetch(`${RECIPES_URL}/search?needle=${encodeURIComponent(needle)}`)).text()); | 68 | remoteResults = JSON.parse(await (await fetch(`${RECIPES_URL}/search?needle=${encodeURIComponent(needle)}`)).text()); |
66 | } | 69 | } |
70 | |||
71 | debug('remoteResults:', remoteResults); | ||
72 | |||
67 | const localResultsArray = (await Recipe.query().where('name', 'LIKE', `%${needle}%`).fetch()).toJSON(); | 73 | const localResultsArray = (await Recipe.query().where('name', 'LIKE', `%${needle}%`).fetch()).toJSON(); |
68 | const localResults = localResultsArray.map(recipe => ({ | 74 | const localResults = localResultsArray.map(recipe => ({ |
69 | id: recipe.recipeId, | 75 | id: recipe.recipeId, |
@@ -71,6 +77,8 @@ class RecipeController { | |||
71 | ...JSON.parse(recipe.data), | 77 | ...JSON.parse(recipe.data), |
72 | })); | 78 | })); |
73 | 79 | ||
80 | debug('localResults:', localResults); | ||
81 | |||
74 | results = [ | 82 | results = [ |
75 | ...localResults, | 83 | ...localResults, |
76 | ...remoteResults || [], | 84 | ...remoteResults || [], |