Score:0

How to dynamically add CORS sites to Google Cloud App Engine Node API

cn flag

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.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.