Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"}'
```
Expand Down Expand Up @@ -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:

Expand Down
2 changes: 1 addition & 1 deletion examples/chekit-core-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
36 changes: 19 additions & 17 deletions scripts/smoke.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
Expand Down
7 changes: 5 additions & 2 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -51,7 +51,10 @@ export function buildServer() {
matchCount: matches.length,
matches
};
});
}

fastify.post('/check', checkIngredients);
fastify.post('/api/check', checkIngredients);

return fastify;
}
Expand Down
Loading