diff --git a/src/index.test.ts b/src/index.test.ts index 5810f37..3415cee 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -72,6 +72,21 @@ describe('nextActuator', () => { }) }) + describe('http methods', () => { + const actuator = nextActuator() + + test('returns 404 when method other than GET is used', async () => { + const { req, res } = httpMocks.createMocks({ + method: 'POST', + url: '/actuator/health' + }) + + await actuator(req, res) + + expect(res._getStatusCode()).toBe(404) + }) + }) + describe('config', () => { it('returns 404 with endpoints disabled', async () => { const actuator = nextActuator({ diff --git a/src/index.ts b/src/index.ts index fc87967..e5f55a6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -21,6 +21,10 @@ export function nextActuator(config: Partial = {}): NextApiHandler { } = config return async (req, res) => { + if (req.method?.toUpperCase() !== 'GET') { + return res.status(404).end() + } + if (req.url == null || req.url === '') { res.status(404).end() return