This repository contains all code to handle CORS in ExpressJS Application
Nowadays when we develop web application often we create different web services that will handle our http requests. Those requests may come from different domain or mobile devices. In this case you need to enable CORS request (Cross-Origin Resource Sharing)
In general if you make a request from web application to a server in different domain and the CORS is not enabled you will get something like this
In ExpressJS application you need to use a middleware to make possible CORS requests https://www.npmjs.com/package/cors
In this repo there are two servers one that start on http://127.0.0.1:5000 and is the api server and other that start on http://127.0.0.1:5001 and serve simple web application that makes request on the previous server.
To install and test the code please follow the following steps:
- Clone or fork the repository
- Go to the local repository folder and digit
npm install
- Once all requested modules have been installed open two different shell screen, point on the project folder and in the first digit
npm start
- In the second shell screen digit
npm run client
Now you can see two different server started now open browser and point to http://localhost:5001/ and enjoy the simple web application that test your api server making http reqiest to it.
I created this repository for all of you have trouble in handle logs in ExpressJS Application. Feel free to send me feedback and issue to improve the example.