-
Notifications
You must be signed in to change notification settings - Fork 676
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
add connInfo in custom handlers #1827
Comments
Everywhere I think this can be closed as already working. Am I missing something? |
let me jump in and ask what's the replacement because it looks deprecated.
I ask because some Applications runs behind a reverse proxy and send the client IP in http headers like Another interesting candidate could be the Proxy Protocol |
Hmmm, that sounds like a different issue to me. I still think this original issue is "already working". Your request sounds like "Fresh should automatically parse export type ServeHandlerInfo = {
/**
* Backwards compatible with std/server
* @deprecated
*/
localAddr?: Deno.NetAddr;
remoteAddr: Deno.NetAddr;
forwardedForAddr?: Deno.NetAddr;
}; But I agree, if this isn't something that gets natively supported in Fresh, it does seem like a good candidate for a plugin providing a single middleware that does this. That way people could just install the plugin, instead of having everyone reinvent the wheel. Additionally, I think only the Edit: I decided to try this out and I did get it working so that |
Okay, then sorry for the hijacking. will create a new issue for that or keep the discussion here? Edit 1:
You are right. There are some Frameworks out there which offers this as middleware. Here a example from a golang framework. https://github.com/go-chi/chi/blob/master/middleware/realip.go
Edit 2: |
I feel like this is something that's easy enough to add as a middleware. I'm not sure if it's a good idea to built that into Fresh by default as it gives a false impression that the header value is trusted. The header value can be easily spoofed and is only somewhat trustworthy if you control the proxy before it and that sets the last value in the This should live in a custom middleware for the projects that need it, not in Fresh itself. |
@marvinhagemeister agree. Is there any middleware overview for fresh? something like "awesome rust" or "awesome golang"? I will try to create such a middleware and create a new issue for that. |
It seems like #1552 is what we need here. |
Then I will create a plugin instead of middleware. |
Well, to elaborate, I was referring to your idea about how to share such a middleware. Currently middleware is specific to your particular project. But you can of course create a plugin which provides a single middleware that extracts the header. The only question is then: how does anyone find your great plugin? We would need some sort of directory, where people can search for Fresh plugins to use. Hence the link to #1552. Edit: https://fresh.deno.dev/docs/concepts/middleware and https://fresh.deno.dev/docs/concepts/plugins#routes-and-middlewares should provide a starting point on how to get this working. https://github.com/deer/fresh_ga4 is an example of a simple plugin providing a google analytics middleware plugin. |
how about to add a "awesome fresh" repo similar to this one for golang https://github.com/avelino/awesome-go |
I have now created #2016 and will try to start to create such a plugin. |
It would be really cool to be able to access connInfo from custom handlers
The text was updated successfully, but these errors were encountered: