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

Astro.clientAddress is not available for Node integration #6451

Closed
1 task done
jcdogo opened this issue Mar 8, 2023 · 6 comments
Closed
1 task done

Astro.clientAddress is not available for Node integration #6451

jcdogo opened this issue Mar 8, 2023 · 6 comments
Assignees
Labels
- P4: important Violate documented behavior or significantly impacts performance (priority)

Comments

@jcdogo
Copy link
Contributor

jcdogo commented Mar 8, 2023

What version of astro are you using?

2.1.2

Are you using an SSR adapter? If so, which one?

@astrojs/node: 5.1.0

What package manager are you using?

npm

What operating system are you using?

Mac

Describe the Bug

When attempting to access Astro.clientAddress, I get this error:

ClientAddressNotAvailable: `Astro.clientAddress` is not available in the `@astrojs/node` adapter. File an issue with the adapter to add support.

It looks like #3973 added support for this to most of the backends, but Node was missing from the list.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-q7ujbk?file=package.json,astro.config.mjs,tsconfig.json&on=stackblitz

Participation

  • I am willing to submit a pull request for this issue.
@matthewp
Copy link
Contributor

matthewp commented Mar 8, 2023

The adapter itself shouldn't need to add support, because it should be getting it for free because it uses this: https://github.com/withastro/astro/blob/main/packages/astro/src/core/app/node.ts#L26-L28

I'll write a test and try it out.

@matthewp matthewp self-assigned this Mar 8, 2023
@matthewp matthewp added the - P3: minor bug An edge case that only affects very specific usage (priority) label Mar 8, 2023
@matthewp
Copy link
Contributor

matthewp commented Mar 8, 2023

This is working on my end. I pulled down your example and it works locally. Are you behind a proxy perhaps?

@matthewp matthewp added needs response Issue needs response from OP and removed - P3: minor bug An edge case that only affects very specific usage (priority) labels Mar 8, 2023
@jcdogo
Copy link
Contributor Author

jcdogo commented Mar 9, 2023

@matthewp Thanks for looking into this. What happens when you click the Stackblitz link from above:
https://stackblitz.com/edit/github-q7ujbk?file=package.json,astro.config.mjs,tsconfig.json&on=stackblitz

Because I'm seeing that error when running on the Stackblitz website directly.

Screen Shot 2023-03-09 at 3 14 30 PM

If it's working for you, maybe we can figure out what the delta is between your environment and the Stackblitz example.

But even if behind a proxy, it shouldn't throw an error right?

@jcdogo
Copy link
Contributor Author

jcdogo commented Mar 10, 2023

I've updated the Stackblitz to astro 2.1.2 and @astrojs/node 5.1.0 and still no luck.

Here's the error stack trace from Stackblitz:

$ astro dev
  🚀  astro  v2.1.2 started in 37ms
  
  ┃ Local    http://localhost:3000/
  ┃ Network  use --host to expose
  
 error   `Astro.clientAddress` is not available in the `@astrojs/node` adapter. File an issue with the adapter to add support.
  File:
    /home/projects/github-q7ujbk/file:/file:/home/projects/github-q7ujbk/node_modules/astro/dist/core/render/result.js:135:21
  Stacktrace:
ClientAddressNotAvailable: `Astro.clientAddress` is not available in the `@astrojs/node` adapter. File an issue with the adapter to add support.
    at get clientAddress [as clientAddress] (file://file:///home/projects/github-q7ujbk/node_modules/astro/dist/core/render/result.js:135:21)
    at Object.default (/home/projects/github-q7ujbk/src/pages/index.astro:14:257)
    at new AstroComponentInstance (/node_modules/astro/dist/runtime/server/render/astro/instance.js:26:32)
    at Module.createAstroComponentInstance (/node_modules/astro/dist/runtime/server/render/astro/instance.js:63:20)
    at Module.renderComponent (/node_modules/astro/dist/runtime/server/render/component.js:296:34)
    at eval (/home/projects/github-q7ujbk/src/pages/index.astro:14:63)
    at index (/node_modules/astro/dist/runtime/server/astro-component.js:22:12)
    at Module.renderPage (file://file:///home/projects/github-q7ujbk/node_modules/astro/dist/runtime/server/render/page.js:106:36)
    at Module.renderPage (file://file:///home/projects/github-q7ujbk/node_modules/astro/dist/core/render/core.js:98:51)
    at async Module.renderPage (file://file:///home/projects/github-q7ujbk/node_modules/astro/dist/core/render/dev/index.js:126:10)

@matthewp If you have this working locally, could you put it on Stackblitz so that I can take a look?

@matthewp matthewp added - P4: important Violate documented behavior or significantly impacts performance (priority) and removed needs response Issue needs response from OP labels Mar 28, 2023
@matthewp
Copy link
Contributor

@jcdogo does that Stackblitz work for you when running locally? It does for me. I think the issue is that Stackblitz doesn't support request.socket.remoteAddress which is what we use in dev.

@matthewp
Copy link
Contributor

Yes, this is a limitation of Stackblitz: https://stackblitz.com/edit/node-qaglfo?file=index.js

Should be working locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P4: important Violate documented behavior or significantly impacts performance (priority)
Projects
None yet
Development

No branches or pull requests

2 participants