Hi saikumarn I have created the endpoint using the khoros documentation. Now when i am hitting the endpoint then it is giving 404 not found. Folder Structure: src > endpoints > CatFact > 1. CatFact.endpoint.json
{
"id": "CatFact",
"httpMethods": ["GET", "POST", "PUT"],
"postBody": "JSON"
}
2. index.ts
import type { EndpointHandlerContext } from 'aurora/externalServerContext';
import type { RouteParameters } from 'express-serve-static-core';
interface CatFactResponse {
message: string;
}
const API = 'https://catfact.ninja/fact';
/**
* This endpoint calls the API at https://catfact.ninja and proxies the response. It also logs the current request URL
* to the plugin log.
* @param context
*/
async function handler(context: EndpointHandlerContext<RouteParameters<string>, CatFactResponse>) {
const {
client: { fetch },
server: { request, response },
utils: { log }
} = context;
log.info('Handling request at', request.originalUrl);
const apiResponse = await fetch(API);
if (apiResponse.ok) {
console.log('ok');
const json = (await apiResponse.json()) as Record<string, unknown>;
return response.json({
message: `Cat fact: ${json.fact}`
});
} else {
console.log('Error ok');
return response.status(apiResponse.status).send({ message: 'Error!' });
}
}
export default handler;
3. package.json
{
"name": "@customer/cat-fact-endpoint",
"version": "1.0.0",
"devDependencies": {
"@types/express": "^4.17.21",
"@types/express-serve-static-core": "^4.17.43",
"@types/qs": "^6.9.13"
}
}
Could you please help me figure out where I might be making a mistake? Thanks!