diff --git a/README.md b/README.md index 46940db..94d9b99 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Then verify: ```bash curl -s http://127.0.0.1:3333/health -curl -s -X POST http://127.0.0.1:3333/check \ +curl -s -X POST http://127.0.0.1:3333/api/check \ -H 'content-type: application/json' \ -d '{"ingredientString":"Water, Cocos Nucifera, Isopropyl Myristate"}' ``` @@ -175,7 +175,9 @@ Returns service health. Returns SQLite ingredient rows and their synonyms. -### `POST /check` +### `POST /api/check` + +Checks an ingredient list. `/check` is also registered locally, but `/api/check` is the recommended hosted endpoint. Request: diff --git a/examples/chekit-core-client.js b/examples/chekit-core-client.js index 0812724..f2ae36b 100644 --- a/examples/chekit-core-client.js +++ b/examples/chekit-core-client.js @@ -47,7 +47,7 @@ export function createChekItCoreClient({ baseUrl = DEFAULT_BASE_URL, fetchImpl = }, checkIngredients({ ingredientString, ingredients, onlyFaceReality = false }) { - return request('/check', { + return request('/api/check', { method: 'POST', body: JSON.stringify({ ingredientString, diff --git a/scripts/smoke.js b/scripts/smoke.js index 59a2246..64b27c3 100644 --- a/scripts/smoke.js +++ b/scripts/smoke.js @@ -24,25 +24,27 @@ upsertIngredients([ const server = buildServer(); try { - const response = await server.inject({ - method: 'POST', - url: '/check', - payload: { - ingredientString: 'Water, Cocos Nucifera, Glycerin' + for (const url of ['/check', '/api/check']) { + const response = await server.inject({ + method: 'POST', + url, + payload: { + ingredientString: 'Water, Cocos Nucifera, Glycerin' + } + }); + + if (response.statusCode !== 200) { + throw new Error(response.body); } - }); - if (response.statusCode !== 200) { - throw new Error(response.body); - } - - const body = JSON.parse(response.body); - if ( - body.matchCount !== 1 - || body.matches[0].name !== 'coconut oil' - || body.matches[0].matchedInputs[0].matchedVia !== 'synonym' - ) { - throw new Error(JSON.stringify(body, null, 2)); + const body = JSON.parse(response.body); + if ( + body.matchCount !== 1 + || body.matches[0].name !== 'coconut oil' + || body.matches[0].matchedInputs[0].matchedVia !== 'synonym' + ) { + throw new Error(JSON.stringify(body, null, 2)); + } } console.log('Smoke test passed.'); diff --git a/src/server.js b/src/server.js index ebdf4b5..a43cbe4 100644 --- a/src/server.js +++ b/src/server.js @@ -31,7 +31,7 @@ export function buildServer() { }; }); - fastify.post('/check', async (request, reply) => { + async function checkIngredients(request, reply) { const body = request.body || {}; const ingredients = parseIngredients(body.ingredients || body.ingredientString); @@ -51,7 +51,10 @@ export function buildServer() { matchCount: matches.length, matches }; - }); + } + + fastify.post('/check', checkIngredients); + fastify.post('/api/check', checkIngredients); return fastify; }