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

Can api_host contain a /path? #408

Open
CoryDanielson opened this issue Jan 4, 2024 · 4 comments
Open

Can api_host contain a /path? #408

CoryDanielson opened this issue Jan 4, 2024 · 4 comments

Comments

@CoryDanielson
Copy link

Can the api_host parameter be set to a directory instead of just a host? I skimmed the code and that appears to be the case, but I just wanted to confirm.

Would this work as expected

mixpanel.init("token-here", {
  api_host: "https://much-proxy.wow/m"
});

Would all requests within the client be sent to much-proxy.wow/m?

@CoryDanielson
Copy link
Author

CoryDanielson commented Jan 4, 2024

Looking through the code samples where api_host is used, and it seems like straight-forward string manipulation. Is there any other known reason why having a proxy with a path would not work?

https://github.com/search?q=repo%3Amixpanel%2Fmixpanel-js+path%3Asrc%2F*+api_host&type=code

@tdumitrescu
Copy link
Member

Your example (api_host: "https://much-proxy.wow/m") will work for now based on the current implementation, but you're essentially relying on an implementation detail. I'd recommend sticking to the api_routes config option if you want to change paths, since that's what it's for.

@CoryDanielson
Copy link
Author

CoryDanielson commented Jan 5, 2024

Your example (api_host: "https://much-proxy.wow/m") will work for now based on the current implementation, but you're essentially relying on an implementation detail. I'd recommend sticking to the api_routes config option if you want to change paths, since that's what it's for.

I actually meant to use the api_host as the base of the URL, and the api_routes to all branch off of that. I'm wondering/clarifying if api_host explicitly needs to be the host portion of the URL, or if it's just a slight misnomer.

mixpanel.init(`my token`, {
  api_host: `https://much-proxy.wow/m`,
  api_routes: {
    track: `foo`,    // https://much-proxy.wow/m/foo
    engage: `bar`,   // https://much-proxy.wow/m/bar
    groups: `baz`,   // https://much-proxy.wow/m/baz
  },
));

I ask because I am interested in setting up the api_proxy as a nested route in an existing service, rather than standing up an entirely new nginx server.


In a test locally, I see this api_host working as I expected/hoped
Screenshot 2024-01-05 at 11 16 07 AM

@tdumitrescu
Copy link
Member

Yes, I'm just saying that you shouldn't rely on that behavior, as it's an implementation detail and might change without warning in future versions. The safer config for you would be:

mixpanel.init(`my token`, {
  api_host: `https://much-proxy.wow`,
  api_routes: {
    track: `m/foo`,    // https://much-proxy.wow/m/foo
    engage: `m/bar`,   // https://much-proxy.wow/m/bar
    groups: `m/baz`,   // https://much-proxy.wow/m/baz
  },
));

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

No branches or pull requests

2 participants