Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross origin #4

Open
wants to merge 7 commits into
base: completed-tutorial
Choose a base branch
from
Open

Cross origin #4

wants to merge 7 commits into from

Conversation

noam-honig
Copy link
Contributor

In this pull request, we change the code not to use proxy in the dev environment and also prepare it to run on separate API / static servers with different URLs - and support for cors.

We follow the article: How to Set up CORS and Cookie-Session in Express

Here are the main changes we've made.

On the backend

  1. We've installed cors
    npm i cors
    npm i @types/cors
  2. In index HTML we've adjusted the cookie-session to support calls from different origins and also have two other behaviors - for dev and production
    https://github.com/remult/react-vite-express-starter/compare/completed-tutorial...cross-origin?expand=1#diff-e4e7a68d82cdfba4e7dab9a32a8f55f3806ffa0cf33f1b8ab64b42941cf68888R13-R38
  3. We've added cors and specified the valid URLs that can send a request to the server.

On the frontend

  1. We've disabled the proxy in the vite.config.ts file.
  2. We've added a file with a const API_URL and used it throughout the code.
  3. We've added a file called .env.production that will include the URL of the actual server once the app is deployed.
  4. We've added `credentials: 'include' to all fetch calls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant