Skip to content

wip: router changes to allow method-not-allowed#2067

Draft
olizilla wants to merge 1 commit intomainfrom
method-not-allowed
Draft

wip: router changes to allow method-not-allowed#2067
olizilla wants to merge 1 commit intomainfrom
method-not-allowed

Conversation

@olizilla
Copy link
Contributor

add tests for

  • GET /login to return 405 Method Not Allowed
  • POST /login to return 401 Unauthorized if auth header not present

initial work on getting router to find path-but-not-method matches

hampered by the GET /:cid route matching GET /login

see #2066

License: (Apache-2.0 AND MIT)
Signed-off-by: Oli Evans oli@tableflip.io

add tests for
- GET /login to return 405 Method Not Allowed
- POST /login to return 401 Unauthorized if auth header not present

initial work on getting router to find path-but-not-method matches

hampered by the `GET /:cid` route matching `GET /login`

see #2066

License: (Apache-2.0 AND MIT)
Signed-off-by: Oli Evans <oli@tableflip.io>
@cloudflare-workers-and-pages
Copy link

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: e04cc59
Status: ✅  Deploy successful!
Preview URL: https://18158d07.nft-storage-1at.pages.dev
Branch Preview URL: https://method-not-allowed.nft-storage-1at.pages.dev

View logs

r.add('get', '/check/:cid', withMode(nftCheck, RO), [postCors])
r.add('get', '', withAuth(withMode(nftList, RO)), [postCors])
r.add('get', '/:cid', withAuth(withMode(nftGet, RO)), [postCors])
r.add('get', /^\/(?<cid>ba\S+|Qm\S+)/i, withAuth(withMode(nftGet, RO)), [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we added:

r.add('get', '/login', () => new Response({ status: 405, statusText: 'Method Not Allowed' }), [postCors])
r.add('get', '/:cid', withAuth(withMode(nftGet, RO)), [postCors])
  • No regex
  • Allows other multibases to be supported if we want

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants