only allow requests from domain express

const express = require('express');
const app = express();

// Middleware to check the request origin
const checkRequestOrigin = (req, res, next) => {
  const allowedDomain = 'yourdomain.com'; // Replace with your domain
  const requestOrigin = req.get('Origin');

  if (requestOrigin && requestOrigin === allowedDomain) {
    res.header('Access-Control-Allow-Origin', requestOrigin);
    next();
  } else {
    res.status(403).json({ error: 'Forbidden: Invalid request origin.' });
  }
};

// Apply the middleware to all routes
app.use(checkRequestOrigin);

// Your routes and other middleware can be defined below this line

// Example route
app.get('/', (req, res) => {
  res.json({ message: 'Welcome to your Express API!' });
});

// Replace 3000 with the desired port number
const port = 3000;

// Start the Express server
app.listen(port, () => {
  console.log(`Server is running on port ${port}`);
});