0

I am new to API deployment.

I have a Node Express API that has CORS enabled in the root app.js, for the API and a socket.io implementation:

var app = express();
app.use(cors({
   origin : ["http://localhost:8080", "http://localhost:8081"],
   credentials: true
}))

and

const httpServer = createServer(app);
const io = new Server(httpServer, { 
    cors: {
        origin: ["http://localhost:8080", "http://localhost:8081"],
        credentials: true,
        methods: ["GET"]
    }
});

I will set up a sales website that allows a customer to pay for a license to use the API with their site, i.e. https://www.example.com

My question is how can I dynamically add the customer's website (say after they submit a form from another site) to the CORS list? Ideally it would be via an API call. The only option which I can think of (that is not automated) is to manually maintain a global js file (i.e. config.js) with the cors list from within the Google platform using the file explorer / editor, and to iterate over it as an array similar to process.env.customerList. This will not work for me as I need to have this step happen automatically.

Any and all suggestions are appreciated.

Leon A
  • 1
  • 1

0 Answers0