Skip to content

Commit

Permalink
fix: return 404 when method other than GET is requested
Browse files Browse the repository at this point in the history
  • Loading branch information
JackCuthbert committed May 10, 2022
1 parent 58e4225 commit accaf4c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export function nextActuator(config: Partial<Config> = {}): 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
Expand Down

0 comments on commit accaf4c

Please sign in to comment.