how to find the origin of the incoming request

Howdy! Is there's a way to find the origin of the incoming request.
let origin = request.headers.get("origin");
let origin = request.headers.get("origin");
return null!
4 Replies
James
James2y ago
Maybe const origin = new URL(request.url).origin
Mohan
MohanOP2y ago
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
const http = require('http');

const server = http.createServer((req, res) => {
const origin = req.headers.origin;
});
const http = require('http');

const server = http.createServer((req, res) => {
const origin = req.headers.origin;
});
Hello, I’m Allie!
Maybe coallesce with the URL origin?
Hello, I’m Allie!
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.
Want results from more Discord servers?
Add your server