Allow localhost JavaScript domain?

Hello,

I apologise if this has been mentioned before, although I was unable to find a solution when I searched through previous posts or the API docs.

I have been attempting to construct some simple queries from a JavaScript application. The application is running on a localhost at the domain http://localhost’. I.e. the ‘Origin’ specified in the request header is ‘http://localhost’.

However, I am unable to enable access by adding ‘http://localhost’, or ‘localhost’ (or any other permutation) as an authorized JavaScript domain. A message appears saying that this is an ‘invalid domain’. Am I missing something here?

How do I enable access for an application on a localhost?

It would be good if the API docs clarified this, assuming this isn’t a stupid question!

Thanks in advance.

3 Likes

Answered my own question (after some trial and error). The problem was fairly trivial, but it had me scratching my head for some time so I’ll post the solution here in case it helps anyone else in a similar situation.

I was unable to add ‘http://localhost’ to the authorized JavaScript domains, so the solution was to create an alias for localhost in my hosts file, in this case modifying /etc/hosts, adding the line:

127.0.0.1 application.com

Then adding ‘http://application.com’ to the authorized JavaScript domains. I think the API expects a URL consisting of three parts, i.e. protocol, second-level and top-level domain. So http://domain.domain

Might I suggest mentioning in the API docs that ‘http://localhost’ is not permitted as an authorized domain?

Hope that helps anyone uncertain how to access the API from localhost domain.

Cheers

1 Like

Thanks for the update.

We have been looking at the security implications of allowing localhost, which basically means that if your API key is compromised, then it could be used by any client that runs from “localhost”. In reality, this appears to be an infinitesimally small risk, so will look to enabling http://localhost in API key registration.

2 Likes

Has http://localhost been enabled yet please?

Same thing. Please update if “localhost” been enabled yet?

we are developing a fintech software in ASP c# and we don’t face any issues using localhost for development.

We call our own API URL which uses HTTP client to fetch companies house API data and we just feed this directly to our own API URL. The benefit of developing this way is to protect your API key. If you make to many requests your IP’s could be banned. So if your key is not easily accessible.

It would be great also to allow localhost:8080.

It failed to accept hartree.stfc.ac.uk, which is a valid domain. Is it using a narrow regex, that rejects ac.uk or maybe rejects domains with too many dots?

Use http://hartree.stfc.ac.uk (or https://…) :wink:

We’ve not yet enabled localhost. It’s on the big feature list of things to do!

1 Like

Hello,

Could you provide an updated status on this subject?

I know a workaround is easy to implement (for example having /etc/hosts 127.0.0.1 localhost localhost.localdomain), but it would still be convenient in some cases to just have localhost like many other API providers allow.

Thank you.

Hello, it would be great for learning ones like me. I gave it up for a while.

Is there an update on this issue?.. I am developing an app on a local webserver, IP address 192.168.blah blah blah, but I cannot register this, which is making development a challenge.

Is there a solution? Or do I have to upload the script to a public domain to test it?

Hello @david,
A workaround is simply to give a hostname to your IP address, by editing /etc/hosts or its equivalent on your OS.

192.168.0.1 localhost my.localdomain

And you can now register my.localdomain as a CH API “JavaScript domains”.

Still, a status update would be appreciated, for something that was already on the backlog in 2015.
Just remove the piece of code preventing localhost as a valid domain name, and you’re done.

thank you for sharing!!

I had faced many issues when I have started developing, But to developers of Quantilytics for helped me a lot to coop up this issue.

We struggled with the same issue. Although the fix is quite simple to implement, once you know how, the user experience of the API could be improved if the CH would allow developers to tick a box which allows requests from localhost.

Is there any way to replicate this using c#, since there is nothing like etc/hosts in c#?