Skip to content

nodeshift-blog-examples/cors-ref-arch-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CORS DEMO

This is a quick demo of how Cross Origin Resource Sharing(CORS) works.

Backend

Step 1: npm install

Step 2: node index.js

A very simple API server using express.js. There is a /greeting endpoint that will return "Hi". When accessing this backend from the frontend code initially, the frontend should throw a CORS error in the Browser Developer Console.

cors error

This can be fixed by using the cors module, which is already part of the backend. Just uncomment the line that adds it to the application in the backends index.js and restart the backend server.

// Comment Out below to enable CORS
// app.use(cors());

Frontend

This is a simple webpage that makes an API call to another domain(the backend server).

To "serve" the page, you can use the serve module by running npx serve in the frontend directory. The host and port will show in the console.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published