I created an API with method GET using express which is working fine.
following is the API
app.get('/healthcheck', (_req, res) => {
res.status(200).send({
state: 'Healthy',
timestamp: new Date(),
uptime: process.uptime()
});
});
I am also getting success response with status = 200 when method is replaced with HEAD or OPTIONS. Shown below.
curl --location --head 'http://localhost:2003/healthcheck'
Although with POST, PUT, PATCH etc methods I am getting status=404.
Since the created API is of type GET, I want to send 404 for all other methods like HEAD, OPTIONS, POST, PATCH etc
only follow request should give status=200
curl --location --request GET 'http://localhost:2003/healthcheck'
How can this be achieved?