From 5f4c2aed0b42bef007ebdfe50576d8b171e9611c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 7 Jun 2025 06:30:04 +0000 Subject: [PATCH 1/3] Initial plan for issue From eee7617e21c9f34a01b4f554af9bb5f66f0a6108 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 7 Jun 2025 06:32:27 +0000 Subject: [PATCH 2/3] Add React proxy configuration section to README for CORS handling Co-authored-by: eklavyamirani <1318529+eklavyamirani@users.noreply.github.com> --- README.md | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/README.md b/README.md index 0442354..a87b04f 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,44 @@ To validate use ```psql -h db -U $PGUSER``` to connect to db. npx create-react-app ``` +### setup proxy for react frontend to communicate with dotnet backend +Add a proxy field to your React app's package.json to handle API calls to the .NET backend: + +```json +{ + "name": "your-react-app", + "version": "0.1.0", + "private": true, + "proxy": "http://localhost:5000", + "dependencies": { + // ... your dependencies + } +} +``` + +This proxy configuration allows your React app (running on port 3000) to make API calls to your .NET backend (running on port 5000) without CORS issues during development. + +Alternatively, you can create a setupProxy.js file in the src folder for more advanced proxy configuration: + +```javascript +const { createProxyMiddleware } = require('http-proxy-middleware'); + +module.exports = function(app) { + app.use( + '/api', + createProxyMiddleware({ + target: 'http://localhost:5000', + changeOrigin: true, + }) + ); +}; +``` + +Note: You'll need to install http-proxy-middleware if using setupProxy.js: +```zsh +npm install --save-dev http-proxy-middleware +``` + ### create dotnet webapi ```zsh dotnet new webapi -o --use-controllers --use-program-main From 7190ad034ed457cc90765c65e29599272c7146a3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 7 Jun 2025 06:38:02 +0000 Subject: [PATCH 3/3] Reorganize proxy section: move after backend setup and add advanced configuration subsection Co-authored-by: eklavyamirani <1318529+eklavyamirani@users.noreply.github.com> --- README.md | 53 ++++++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index a87b04f..612d971 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,33 @@ To validate use ```psql -h db -U $PGUSER``` to connect to db. npx create-react-app ``` +### create dotnet webapi +```zsh +dotnet new webapi -o --use-controllers --use-program-main +``` + +### create dotnet gitignore +```zsh +dotnet new gitignore +``` + +### create new controller +```zsh +dotnet new apicontroller --actions --name +``` + +### for devmode, enable cors +```csharp +app.UseCors(builder => + builder.AllowAnyOrigin() + .AllowAnyMethod() + .AllowAnyHeader() +); +``` + ### setup proxy for react frontend to communicate with dotnet backend + +#### Basic Configuration Add a proxy field to your React app's package.json to handle API calls to the .NET backend: ```json @@ -28,7 +54,8 @@ Add a proxy field to your React app's package.json to handle API calls to the .N This proxy configuration allows your React app (running on port 3000) to make API calls to your .NET backend (running on port 5000) without CORS issues during development. -Alternatively, you can create a setupProxy.js file in the src folder for more advanced proxy configuration: +#### Advanced Configuration +For more complex proxy scenarios, you can create a setupProxy.js file in the src folder: ```javascript const { createProxyMiddleware } = require('http-proxy-middleware'); @@ -48,27 +75,3 @@ Note: You'll need to install http-proxy-middleware if using setupProxy.js: ```zsh npm install --save-dev http-proxy-middleware ``` - -### create dotnet webapi -```zsh -dotnet new webapi -o --use-controllers --use-program-main -``` - -### create dotnet gitignore -```zsh -dotnet new gitignore -``` - -### create new controller -```zsh -dotnet new apicontroller --actions --name -``` - -### for devmode, enable cors -```csharp -app.UseCors(builder => - builder.AllowAnyOrigin() - .AllowAnyMethod() - .AllowAnyHeader() -); -```