Skip to content
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 behindProxy option to App.listen() #2663

Closed
wants to merge 1 commit into from

Conversation

dahlia
Copy link

@dahlia dahlia commented Sep 30, 2024

Addresses #2660.

The behindProxy option lets Fresh respect X-Forwarded-Proto, X-Forwarded-Host, X-Forwarded-Port, and X-Forwarded-For headers (if any). This is useful when Fresh is behind a reverse proxy like nginx or Caddy.

Copy link
Collaborator

@marvinhagemeister marvinhagemeister left a comment

Choose a reason for hiding this comment

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

Thanks for making a PR. I feel like this is much better implemented as a middleware instead of a configuration option as it's not something everyone needs. With Fresh 2 the aim is to keep the config as minimal as possible.

@dahlia
Copy link
Author

dahlia commented Oct 1, 2024

@marvinhagemeister Does Fresh's middleware support replacing request objects? At first glance, it doesn't seem to support that.

@marvinhagemeister
Copy link
Collaborator

Yes, to replace the Request object do this:

function proxyMiddleware(ctx) {
  const req =  new Request()
  
  // Replace current request
  ctx.req = req;
  ctx.url = new URL(req.url)
  
  return ctx.next()
}

@dahlia
Copy link
Author

dahlia commented Oct 2, 2024

@marvinhagemeister Apparently FreshContext.req is readonly. Should I suppress the TypeScript error and set ctx.req by force?

@marvinhagemeister
Copy link
Collaborator

Let's remove the readonly in FreshContext.

dahlia added a commit to dahlia/fresh that referenced this pull request Nov 6, 2024
@dahlia
Copy link
Author

dahlia commented Nov 6, 2024

Let's remove the readonly in FreshContext.

@marvinhagemeister: Just opened a separate pull request.

@dahlia dahlia closed this Nov 6, 2024
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