sef-global / scholarx-backend

This is the backend of the ScholarX
MIT License
8 stars 32 forks source link

Implementing CORS Configuration in Express.js Server #88

Closed mayura-andrew closed 6 months ago

mayura-andrew commented 6 months ago

Description: We need to add CORS configuration to our Express app to allow it to accept requests from 'http://localhost:5173'. This will allow the server to accept requests from different origins, perform HTTP methods, and allow session cookies to pass through.

Tasks:

Add CORS middleware to the Express app. Configure CORS to accept requests from 'http://localhost:5173'. Allow 'GET, HEAD, PUT, PATCH, DELETE' methods. Set 'credentials' to true to allow session cookies to pass through.


app.use(
  cors({
    origin: 'http://localhost:5173', // allow to server to accept request from different origin
    methods: 'GET, HEAD, PUT, PATCH, DELETE', // allow to perform http methods
    credentials: true // allow session cookie from browser to pass through
  })
)

Acceptance Criteria:

The server should be able to accept requests from 'http://localhost:5173'. The server should be able to perform 'GET, HEAD, PUT, PATCH, DELETE' methods. The server should allow session cookies to pass through. Additional Information: This change is necessary for our frontend at 'http://localhost:5173' to be able to communicate with our backend.

Related Dependencies or References:

CORS middleware: https://www.npmjs.com/package/cors Express.js: https://expressjs.com/