SSR & does not append headers. #365

Closed
opened 2025-08-09 17:16:00 +00:00 by fergalmoran · 0 comments
Owner

Originally created by @rohan-buechner on 10/13/2017

I have an Isomorphic white-labelled app of sorts that needs to be able to differentiate its data by means of supplying a header to each request. EG:

We'll be able to spawn up a new web app & api for a type of product, but then by means of some clever proxy work, we want to be able to expose a web app to different countries via a host name change of sorts. (This difference is required to segregate data at the back end)

1. www.web.foo.usa.com 
2. www.web.foo.za.com

The API

1. www.api.foo.com

I have an endpoint that looks like this:

 public string search(string text)
 {
     StringValues foo = "";
     if (Request.Headers.TryGetValue("Origin", out foo))
     {
        Console.WriteLine(foo.ToString());
     }
     
     return "bar";
 }

When doing a regular Ajax fetch from my front end app, I will see a log entry in the console that matches my origin.

www.web.foo.za.com    // thus this was a successful log

BUT..

On the very first request (on server pre-render), or when I disable javascript (no ajax)/ cache clear & hard reload (pre-render again), Origin seems to be empty... even though the request is successful. (Meaning the ServerSideRenderer completed the request).

Wireshark, seems to confirm my suspicions...

Regular request:
AJAX REQUEST

SSR Request:
SSR

Question:

When SSR is taking place, how do I detect the actual origin of the request?

*Originally created by @rohan-buechner on 10/13/2017* I have an Isomorphic white-labelled app of sorts that needs to be able to differentiate its data by means of supplying a header to each request. EG: We'll be able to spawn up a new web app & api for a type of product, but then by means of some clever proxy work, we want to be able to expose a web app to different countries via a host name change of sorts. (This difference is required to segregate data at the back end) 1. www.web.foo.usa.com 2. www.web.foo.za.com The API 1. www.api.foo.com I have an endpoint that looks like this: public string search(string text) { StringValues foo = ""; if (Request.Headers.TryGetValue("Origin", out foo)) { Console.WriteLine(foo.ToString()); } return "bar"; } When doing a regular Ajax fetch from my front end app, I will see a log entry in the console that matches my origin. www.web.foo.za.com // thus this was a successful log BUT.. On the very first request (on server pre-render), or when I disable javascript (no ajax)/ cache clear & hard reload (pre-render again), `Origin` seems to be empty... even though the request is successful. (Meaning the ServerSideRenderer completed the request). Wireshark, seems to confirm my suspicions... **Regular request:** [![AJAX REQUEST][1]][1] **SSR Request:** [![SSR][2]][2] **Question:** When SSR is taking place, how do I detect the actual origin of the request? [1]: https://i.stack.imgur.com/WTUN5.png [2]: https://i.stack.imgur.com/LhctM.png
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/JavaScriptServices#365
No description provided.