# Allow localhost JavaScript domain?

**URL:** <http://forum.companieshouse.gov.uk/t/allow-localhost-javascript-domain/83>\
**Category:** Uncategorized\
**Created:** [May 17, 2015, 10:43pm UTC](http://forum.companieshouse.gov.uk/t/allow-localhost-javascript-domain/83 "2015-05-17T22:43:46Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tom\_Roberts](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/t/ce73a5/32.png) [@Tom\_Roberts](http://forum.companieshouse.gov.uk/u/Tom_Roberts)\
**Post date:** [May 17, 2015, 10:43pm UTC](http://forum.companieshouse.gov.uk/t/allow-localhost-javascript-domain/83/1 "2015-05-17T22:43:46Z")

</div>

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](http://localhost)’. I.e. the ‘Origin’ specified in the request header is ‘[http://localhost](http://localhost)’.

However, I am unable to enable access by adding ‘[http://localhost](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.

---

<div class="post-metadata">

**Author:** ![Tom\_Roberts](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/t/ce73a5/32.png) [@Tom\_Roberts](http://forum.companieshouse.gov.uk/u/Tom_Roberts)\
**Post date:** [May 19, 2015, 10:00pm UTC](http://forum.companieshouse.gov.uk/t/allow-localhost-javascript-domain/83/2 "2015-05-19T22:00:20Z")

</div>

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](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](http://application.com)

Then adding ‘[http://application.com](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](http://domain.domain)

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

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

Cheers

---

<div class="post-metadata">

**Author:** ![csmith](http://forum.companieshouse.gov.uk/user_avatar/forum.companieshouse.gov.uk/csmith/32/8_2.png) [@csmith](http://forum.companieshouse.gov.uk/u/csmith)\
**Post date:** [May 21, 2015, 1:32pm UTC](http://forum.companieshouse.gov.uk/t/allow-localhost-javascript-domain/83/3 "2015-05-21T13:32:07Z")

</div>

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](http://localhost) in API key registration.

---

<div class="post-metadata">

**Author:** ![frank](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/f/3d9bf3/32.png) [@frank](http://forum.companieshouse.gov.uk/u/frank)\
**Post date:** [June 21, 2015, 3:09pm UTC](http://forum.companieshouse.gov.uk/t/allow-localhost-javascript-domain/83/4 "2015-06-21T15:09:37Z")

</div>

Has [http://localhost](http://localhost) been enabled yet please?

---

<div class="post-metadata">

**Author:** ![mohit](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/m/c68b51/32.png) [@mohit](http://forum.companieshouse.gov.uk/u/mohit)\
**Post date:** [June 23, 2015, 10:42am UTC](http://forum.companieshouse.gov.uk/t/allow-localhost-javascript-domain/83/5 "2015-06-23T10:42:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jordan\_hall](http://forum.companieshouse.gov.uk/user_avatar/forum.companieshouse.gov.uk/jordan_hall/32/113_2.png) [@jordan\_hall](http://forum.companieshouse.gov.uk/u/jordan_hall)\
**Post date:** [August 25, 2015, 1:08pm UTC](http://forum.companieshouse.gov.uk/t/allow-localhost-javascript-domain/83/6 "2015-08-25T13:08:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![chris\_morris](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/c/6de8d8/32.png) [@chris\_morris](http://forum.companieshouse.gov.uk/u/chris_morris)\
**Post date:** [December 1, 2015, 3:03pm UTC](http://forum.companieshouse.gov.uk/t/allow-localhost-javascript-domain/83/7 "2015-12-01T15:03:06Z")

</div>

It would be great also to allow localhost:8080.

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

---

<div class="post-metadata">

**Author:** ![csmith](http://forum.companieshouse.gov.uk/user_avatar/forum.companieshouse.gov.uk/csmith/32/8_2.png) [@csmith](http://forum.companieshouse.gov.uk/u/csmith)\
**Post date:** [December 1, 2015, 4:39pm UTC](http://forum.companieshouse.gov.uk/t/allow-localhost-javascript-domain/83/8 "2015-12-01T16:39:52Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![anthony\_drogon](http://forum.companieshouse.gov.uk/user_avatar/forum.companieshouse.gov.uk/anthony_drogon/32/1082_2.png) [@anthony\_drogon](http://forum.companieshouse.gov.uk/u/anthony_drogon)\
**Post date:** [August 9, 2016, 1:04am UTC](http://forum.companieshouse.gov.uk/t/allow-localhost-javascript-domain/83/9 "2016-08-09T01:04:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![petr\_hnilica](http://forum.companieshouse.gov.uk/user_avatar/forum.companieshouse.gov.uk/petr_hnilica/32/462_2.png) [@petr\_hnilica](http://forum.companieshouse.gov.uk/u/petr_hnilica)\
**Post date:** [October 3, 2017, 6:41pm UTC](http://forum.companieshouse.gov.uk/t/allow-localhost-javascript-domain/83/10 "2017-10-03T18:41:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![david](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](http://forum.companieshouse.gov.uk/u/david)\
**Post date:** [November 29, 2017, 9:40pm UTC](http://forum.companieshouse.gov.uk/t/allow-localhost-javascript-domain/83/11 "2017-11-29T21:40:31Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![antoine](http://forum.companieshouse.gov.uk/user_avatar/forum.companieshouse.gov.uk/antoine/32/1082_2.png) [@antoine](http://forum.companieshouse.gov.uk/u/antoine)\
**Post date:** [February 1, 2018, 12:11pm UTC](http://forum.companieshouse.gov.uk/t/allow-localhost-javascript-domain/83/12 "2018-02-01T12:11:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![zarawymark121](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/z/91b2a8/32.png) [@zarawymark121](http://forum.companieshouse.gov.uk/u/zarawymark121)\
**Post date:** [November 28, 2018, 4:03pm UTC](http://forum.companieshouse.gov.uk/t/allow-localhost-javascript-domain/83/13 "2018-11-28T16:03:03Z")

</div>

thank you for sharing!!

---

<div class="post-metadata">

**Author:** ![zarawymark121](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/z/91b2a8/32.png) [@zarawymark121](http://forum.companieshouse.gov.uk/u/zarawymark121)\
**Post date:** [November 28, 2018, 4:04pm UTC](http://forum.companieshouse.gov.uk/t/allow-localhost-javascript-domain/83/14 "2018-11-28T16:04:13Z")

</div>

I had faced many issues when I have started developing, But to developers of [Quantilytics](https://www.quantilytics.org/) for helped me a lot to coop up this issue.

---

<div class="post-metadata">

**Author:** ![Sam76](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/s/35a633/32.png) [@Sam76](http://forum.companieshouse.gov.uk/u/Sam76)\
**Post date:** [December 7, 2018, 1:31pm UTC](http://forum.companieshouse.gov.uk/t/allow-localhost-javascript-domain/83/15 "2018-12-07T13:31:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![bernardboakye](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/b/bcef8e/32.png) [@bernardboakye](http://forum.companieshouse.gov.uk/u/bernardboakye)\
**Post date:** [October 28, 2020, 10:19pm UTC](http://forum.companieshouse.gov.uk/t/allow-localhost-javascript-domain/83/16 "2020-10-28T22:19:06Z")

</div>

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