# How does replica know which canister to serve from

**URL:** <https://forum.dfinity.org/t/how-does-replica-know-which-canister-to-serve-from/2438>\
**Category:** Developers\
**Created:** [April 9, 2021, 10:59pm UTC](https://forum.dfinity.org/t/how-does-replica-know-which-canister-to-serve-from/2438 "2021-04-09T22:59:03Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![lastmjs](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/lastmjs/32/3406_2.png) [@lastmjs](https://forum.dfinity.org/u/lastmjs)\
**Post date:** [April 9, 2021, 10:59pm UTC](https://forum.dfinity.org/t/how-does-replica-know-which-canister-to-serve-from/2438/1 "2021-04-09T22:59:03Z")

</div>

Running into the problems described here: [Dfx 0.7.0-beta.2 does not allow ES modules](https://forum.dfinity.org/t/dfx-0-7-0-beta-2-does-not-allow-es-modules/2430), and I am trying to figure out how to get this all to work using a local http proxy for now.

For a GET request, how does the replica know which canister to get the assets from? Inspecting some of the traffic, it seems like it must be the `Referrer` http header, because not all GET requests have the `canisterId` appended to their paths.

I’m playing with this locally but getting 500 errors from dependencies of my ES modules.

---

<div class="post-metadata">

**Author:** ![lastmjs](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/lastmjs/32/3406_2.png) [@lastmjs](https://forum.dfinity.org/u/lastmjs)\
**Post date:** [April 9, 2021, 11:07pm UTC](https://forum.dfinity.org/t/how-does-replica-know-which-canister-to-serve-from/2438/2 "2021-04-09T23:07:25Z")

</div>

Okay I think I figured it out, it’s got to be the `Referer` header. When I set that to the empty string I get a 500, and when I manually put a `canisterId` into it I don’t get 500 errors anymore.

So ES modules are indeed unsupported currently with the `v0.7.0` beta, since the `Referer` does not have the canisterId. I am assuming other things besides ES modules are broken, essentially whenever a request is not originating from the route index.html file, there might be a possibility of this being broken.

---

<div class="post-metadata">

**Author:** ![nomeata](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/nomeata/32/733_2.png) [@nomeata](https://forum.dfinity.org/u/nomeata)\
**Post date:** [April 20, 2021, 8:35am UTC](https://forum.dfinity.org/t/how-does-replica-know-which-canister-to-serve-from/2438/3 "2021-04-20T08:35:07Z")

</div>

Sorry, late repsonse, but it’s not the referrer. Eventually it will be the `Host` (`canister-id.ic0.app`); for local development a query parameter `?canister_id=abcde-fgh` is used.

---

<div class="post-metadata">

**Author:** ![lastmjs](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/lastmjs/32/3406_2.png) [@lastmjs](https://forum.dfinity.org/u/lastmjs)\
**Post date:** [April 20, 2021, 12:29pm UTC](https://forum.dfinity.org/t/how-does-replica-know-which-canister-to-serve-from/2438/4 "2021-04-20T12:29:39Z")

</div>

I’m sorry, but are you sure it’s not the referer locally? Like I explained in my previous post, I get 500 errors when the referer header does not have the canisterId query parameter in it.

The problem is, many requests locally do not have the canisterId query parameter anywhere in the headers that I can see. If you look through some of my other posts, I’ve explained that ES module transitive import requests do not have the canisterId query parameter anywhere in the request. These requests fail. But when I put the canisterId query parameter into the referer header (using a proxy), the requests succeed.

My experiments locally do not match what you’re saying, so I have to disagree.

---

<div class="post-metadata">

**Author:** ![lastmjs](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/lastmjs/32/3406_2.png) [@lastmjs](https://forum.dfinity.org/u/lastmjs)\
**Post date:** [April 20, 2021, 12:31pm UTC](https://forum.dfinity.org/t/how-does-replica-know-which-canister-to-serve-from/2438/5 "2021-04-20T12:31:30Z")

</div>

Or, I can’t square what you’re saying with what I’m seeing locally I guess. What am I doing wrong? I assume you would be able to replicate my issues locally

---

<div class="post-metadata">

**Author:** ![anon74414410](https://avatars.discourse-cdn.com/v4/letter/a/85f322/32.png) [@anon74414410](https://forum.dfinity.org/u/anon74414410)\
**Post date:** [April 20, 2021, 1:04pm UTC](https://forum.dfinity.org/t/how-does-replica-know-which-canister-to-serve-from/2438/6 "2021-04-20T13:04:00Z")

</div>

Best solution I’ve found is to use `http://canisterId.localhost:8000` and to mostly develop on chrome, which supports localhost subdomains, or else to use Webpack dev server

---

<div class="post-metadata">

**Author:** ![nomeata](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/nomeata/32/733_2.png) [@nomeata](https://forum.dfinity.org/u/nomeata)\
**Post date:** [April 20, 2021, 2:09pm UTC](https://forum.dfinity.org/t/how-does-replica-know-which-canister-to-serve-from/2438/7 "2021-04-20T14:09:45Z")

</div>

> [@lastmjs](#):
>
> My experiments locally do not match what you’re saying, so I have to disagree.

That would be odd; I don’t see any code using the referrer in any component that could play a role here, and I never heard about this.

Maybe the requests you are seeing without the url query parameter are not `GET` request to `/api/…`, which are interaction with the internet computer?

For `GET`s to assets, the canister id must come from somewhere, and as far I know, that is either the query parameter, or the hostname (as @anon74414410 points out). If you obsere something else I’d be curious to have more detail, e.g. a dump of the request as captured from the dev console.

---

<div class="post-metadata">

**Author:** ![lastmjs](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/lastmjs/32/3406_2.png) [@lastmjs](https://forum.dfinity.org/u/lastmjs)\
**Post date:** [April 20, 2021, 3:25pm UTC](https://forum.dfinity.org/t/how-does-replica-know-which-canister-to-serve-from/2438/8 "2021-04-20T15:25:10Z")

</div>

Cool, I’ll see if I can get more information

---

<div class="post-metadata">

**Author:** ![nomeata](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/nomeata/32/733_2.png) [@nomeata](https://forum.dfinity.org/u/nomeata)\
**Post date:** [May 6, 2021, 7:52am UTC](https://forum.dfinity.org/t/how-does-replica-know-which-canister-to-serve-from/2438/9 "2021-05-06T07:52:46Z")

</div>

Looks like you were right and I was wrong, to some extend.

In _local development_ the proxy ran by `dfx start` will indeed look for the canister id in the following locations:

- Hostname
- Query string
- Referrer

The latter two are only needed for local development where you can’t easily have separate hostnames per canister; for the real deployment, the hostname should always be indicative.

Sorry for being thick-headed here!

---

<div class="post-metadata">

**Author:** ![lastmjs](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/lastmjs/32/3406_2.png) [@lastmjs](https://forum.dfinity.org/u/lastmjs)\
**Post date:** [May 18, 2021, 3:51pm UTC](https://forum.dfinity.org/t/how-does-replica-know-which-canister-to-serve-from/2438/10 "2021-05-18T15:51:55Z")

</div>

Oh cool, yeah it’s no problem at all! Thanks for getting back to me on this

---

<div class="post-metadata">

**Author:** ![lastmjs](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/lastmjs/32/3406_2.png) [@lastmjs](https://forum.dfinity.org/u/lastmjs)\
**Post date:** [May 19, 2021, 11:41pm UTC](https://forum.dfinity.org/t/how-does-replica-know-which-canister-to-serve-from/2438/11 "2021-05-19T23:41:49Z")

</div>

This seems to work for now, I’ll update this thread if there are any issues with using localhost subdomains.

---

<div class="post-metadata">

**Author:** ![lastmjs](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/lastmjs/32/3406_2.png) [@lastmjs](https://forum.dfinity.org/u/lastmjs)\
**Post date:** [May 20, 2021, 3:29pm UTC](https://forum.dfinity.org/t/how-does-replica-know-which-canister-to-serve-from/2438/12 "2021-05-20T15:29:48Z")

</div>

I think using localhost subdomains might be breaking update calls in development: [Fail to verify certificate in development update calls](https://forum.dfinity.org/t/fail-to-verify-certificate-in-development-update-calls/4078)

---

<div class="post-metadata">

**Author:** ![lastmjs](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/lastmjs/32/3406_2.png) [@lastmjs](https://forum.dfinity.org/u/lastmjs)\
**Post date:** [May 20, 2021, 4:32pm UTC](https://forum.dfinity.org/t/how-does-replica-know-which-canister-to-serve-from/2438/13 "2021-05-20T16:32:44Z")

</div>

Turns out they weren’t!

---

<div class="post-metadata">

**Author:** ![paulyoung](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/paulyoung/32/5251_2.png) [@paulyoung](https://forum.dfinity.org/u/paulyoung)\
**Post date:** [May 13, 2022, 3:28am UTC](https://forum.dfinity.org/t/how-does-replica-know-which-canister-to-serve-from/2438/14 "2022-05-13T03:28:42Z")

</div>

`icx-proxy --fetch-root-key --address 127.0.0.1:1234 --dns-alias foo.localhost:<asset-canister-id>` allows browsing to [http://foo.localhost:1234](http://foo.localhost:1234) in Chrome.
