Hello I am using Nginx with NodeJS on Ubuntu 20.04 to set up a reverse proxy server to host a NodeJS Typescript API using PM2.
I have enabled CORS in the Nginx default file as well as in the TS file headers. However when I try to make a http request to the API in my Angular front-end I still get CORS error.
The API is hosting fine and can be accessed in the web browser to get a simple response.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
To disable CORS for your Node.js API, you will need to configure Nginx to add the necessary CORS headers to the response from your API.
Here is an example of how you might do this in your Nginx configuration:
This configuration tells Nginx to pass requests to the
/apipath to the Node.js API running on port 3000, and to add the necessary CORS headers to the response. The add_header directives specify the values for the
Keep in mind that you may also need to configure CORS in your Node.js API itself, depending on how it is implemented. For example, if you are using the
corslibrary, you can use the
cors()middleware to enable CORS for your API.