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

default port on localhost #30

Closed
mathisonian opened this issue Nov 6, 2017 · 7 comments
Closed

default port on localhost #30

mathisonian opened this issue Nov 6, 2017 · 7 comments

Comments

@mathisonian
Copy link

When I'm running a server on localhost on some port, say 3000, and use d3-request to reference a file from the root url, e.g.

const d3 = require('d3-request');
d3.json('/my-data.json', ...)

this sends a GET request to http://localhost/my-data.json, while I'd expect it to be routed to http://localhost:3000/my-data.json. To be clear the javascript and html is loading from localhost:3000 as well in this case.

Using superagent or this ajax snippet from SO I can request /my-data.json and it is fetched correctly.

@mbostock
Copy link
Member

mbostock commented Nov 6, 2017

Unable to reproduce. This worked fine for me using http-server -p 3000.

https://gist.github.com/mbostock/fd652a3fc1a41243d92e2cee6cbd6711

@mbostock mbostock closed this as completed Nov 6, 2017
@mathisonian
Copy link
Author

I'm able to consistently reproduce this, but only in a commonjs environment. I ran your code locally and it worked as expected, and tested using rollup to build a bundle (repo here) and that also worked as expected.

However, using commonjs I get the behavior described above, unclear why. To reproduce easily, I've made a repo to help reproduce the problem: https://github.com/mathisonian/d3-request-test-cjs.

@mbostock
Copy link
Member

mbostock commented Nov 9, 2017

It’s because you are consuming the code that is targeted at Node and has an XMLHttpRequest polyfill, rather than code targeted at the browser. You need to use the module entry point if you are using a browser-targeting bundle. (Or, you can rebundle the UMD provided with the release.)

@mathisonian
Copy link
Author

Got it - thanks @mbostock.

@mbostock
Copy link
Member

mbostock commented Nov 9, 2017

You are very welcome! Sorry for the lost time.

@naxxateux
Copy link

Thanks @mathisonian and @mbostock. You saved my day.

@briantjacobs
Copy link

briantjacobs commented Jan 16, 2018

I'm having the same issue here using d3.json within a node environment (browserify). Can someone on this thread just explain what "module entry point" means here and the specific step you took to fix this?

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

No branches or pull requests

4 participants