how to find the origin of the incoming request
Howdy! Is there's a way to find the origin of the incoming request.
return null!
4 Replies
Maybe
const origin = new URL(request.url).origin
Not the url origin! But the origin of the web request from which the request is being made.
"The "Origin" header in HTTP refers to the origin of a web request, which indicates the scheme (protocol), domain, and port from which the request is being made. It provides information about the source of the request and is primarily used as a security mechanism in the context of cross-origin resource sharing (CORS)."
In Node.js we can get the origin by
Maybe coallesce with the URL origin?
Since it isn’t always defined https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Origin#description
Origin - HTTP | MDN
The Origin request header indicates the origin (scheme, hostname, and port) that caused the request.
For example, if a user agent needs to request resources included in a page, or fetched by scripts that it executes, then the origin of the page may be included in the request.