Mark Thien
Mark Thien

Reputation: 1167

Get url that access your API express.js

I am using node.js with express.js. I am exposing some API and I want my API will only entertain request from my website.

for example, user A using my website https://abc123.com and make some request like login and if node.js/express.js detect that the request is from https://abc123.com then proceed else just ignore.

I do not want anyone the access my API from their local machine or using their program.

Upvotes: 0

Views: 244

Answers (3)

ddos-san
ddos-san

Reputation: 146

For get url that acces at you API in express.js use "get" methode from "request". See documentation

const origin = req.get('origin');

Upvotes: 0

user10124491
user10124491

Reputation:

I would use CORS, it allows you to specify to the browser what domains are allowed to access the page, and the browser will prevent the site from accessing your API if the domain is not allowed.

Upvotes: 0

user3307291
user3307291

Reputation: 803

You would need to send a secure token along with each request so that only valid user get to access the system and APIs.

Upvotes: 1

Related Questions