-
Notifications
You must be signed in to change notification settings - Fork 724
Feature/add ip restriction middleware #3035
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Feature/add ip restriction middleware #3035
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First pass
src/middlewares/ip_restriction.ts
Outdated
export type AddressType = "IPv4" | "IPv6"; | ||
|
||
export type NetAddrInfo = { | ||
/** | ||
* Transport protocol type | ||
*/ | ||
transport?: "tcp" | "udp"; | ||
/** | ||
* Transport port number | ||
*/ | ||
port: number; | ||
address: string; | ||
addressType?: AddressType; | ||
}; | ||
|
||
export interface ConnInfo { | ||
/** | ||
* Remote information | ||
*/ | ||
remote: NetAddrInfo; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These types already exist within the Deno runtime API. See https://docs.deno.com/api/deno/network.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Each test should be wrapped in a Deno.test()
call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iuioiua san.
Thanks for your comment!
Sorry if I’m mistaken, but I thought when writing in a BDD style, Deno.test would be replaced by describe. Was I incorrect about that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked at the other code as well.
I understand now that using Deno.test instead of a BDD style is the standard.
I’ll prepare a fix.
src/middlewares/ip_restriction.ts
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a lot of IP address logic here that might be valuable in other domains. I recommend creating an issue for the Standard Library for any useful utilities to @std/net
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The part you’re pointing out is indeed a generic utility — in Hono, it’s placed in utils as well.
I’ll go ahead and create an issue for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have created an issue.Thanks.
denoland/std#6722
@iuioiua |
Why was this PR initiated?
I opened an issue and held discussions about officially providing middleware in Fresh by porting middleware from Hono.
#3011
What does this PR do?
I introduced the IP Restriction middleware bundled with Fresh by porting the IP Restriction middleware from Hono.
I appreciate your review.