Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
c14c5e9
fix: resolve CORS issues by proxying API requests in Vite and Nginx
abhishekblue Nov 28, 2025
7422f3c
fix: address code review feedback (regex, security, ws support)
abhishekblue Nov 28, 2025
9a8f620
chore: remove redundant secure flag from vite config
abhishekblue Nov 28, 2025
620c42c
chore: make proxy target configurable via env var
abhishekblue Nov 28, 2025
9ce303c
fix: address review comments
abhishekblue Nov 29, 2025
f4f916a
fix: make proxy target configurable via TALAWA_API_URL env var
abhishekblue Nov 29, 2025
077878d
chore: add detailed comment in .env.example
abhishekblue Nov 29, 2025
bbe96c4
chore: updated detailed comment in .env.example
abhishekblue Nov 29, 2025
bbfbadc
fix: implement suggested fix for based on REACT_APP_TALAWA_URL
abhishekblue Dec 1, 2025
01cf5d0
docs: add explicit REACT_APP_TALAWA_URL examples for all scenarios
abhishekblue Dec 8, 2025
992944d
docs: remove obsolete WebSocket var from config
abhishekblue Dec 8, 2025
965b2dc
fix: addressing coderaabitai requested changes, add unit tests
abhishekblue Dec 10, 2025
204e3fc
fix: improved config/vite.config.ts as per coderabbitai suggestion
abhishekblue Dec 10, 2025
3ce3fa8
fix: resolve CORS via proxy config, update docs, and fix client-side …
abhishekblue Dec 11, 2025
baed561
updated configuration.md
abhishekblue Dec 11, 2025
ec88c45
Merge branch 'develop' into fix/xss-cors
abhishekblue Dec 11, 2025
0f8cd17
fix: resolve linting errors
abhishekblue Dec 11, 2025
d66d892
Merge branch 'fix/xss-cors' of https://github.com/abhishekblue/talawa…
abhishekblue Dec 11, 2025
feb6b2b
fix: resolved failing tests for src/screens/LoginPage/LoginPage.tsx
abhishekblue Dec 11, 2025
67c4c1a
fix: remove duplication in login tests and close br tags
abhishekblue Dec 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ PORT=4321

# Run Talawa-api locally in your system, and put its url into the same.

REACT_APP_TALAWA_URL=http://localhost:4000/graphql
REACT_APP_TALAWA_URL=/graphql

# Do you want to setup and use "I'm not a robot" Checkbox (Google Recaptcha)?
# If no, leave blank, else write yes
Expand All @@ -24,7 +24,7 @@ REACT_APP_USE_RECAPTCHA=
REACT_APP_RECAPTCHA_SITE_KEY=

# has to be inserted in the env file to use websocket based features.
REACT_APP_BACKEND_WEBSOCKET_URL=ws://localhost:4000/graphql
REACT_APP_BACKEND_WEBSOCKET_URL=/graphql

# If you want to logs Compiletime and Runtime error , warning and info write YES or if u want to
# keep the console clean leave it blank
Expand Down
10 changes: 4 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ If you are new to contributing to open source, please read the Open Source Guide

<!-- toc -->

- [Contributing to Talawa-Admin](#contributing-to-talawa-admin)
- [Table of Contents](#table-of-contents)
- [General](#general)
- [Testing and Code Quality](#testing-and-code-quality)
- [Quick Reference](#quick-reference)
- [Making Contributions](#making-contributions)
- [General](#general)
- [Testing and Code Quality](#testing-and-code-quality)
- [Quick Reference](#quick-reference)
- [Making Contributions](#making-contributions)

<!-- tocstop -->

Expand Down
21 changes: 21 additions & 0 deletions config/docker/setup/apache.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<VirtualHost *:80>
ServerName localhost
DocumentRoot /usr/share/nginx/html
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Why was this added?
  2. Why does it refer to nginx?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for reviewing!

  1. I added this file because the comment suggestion mentioned adding an apache.conf example as a guide.

  2. The Nginx path was a copy-paste mistake on my part. I have fixed it to use the standard Apache path (/usr/local/apache2/htdocs) in the latest commit.


# Proxy GraphQL requests to the internal API container
ProxyPass /graphql http://api:4000/graphql
ProxyPassReverse /graphql http://api:4000/graphql

# Handle WebSocket upgrades
RewriteEngine On
RewriteCond %{HTTP:Upgrade} =websocket [NC]
RewriteRule /graphql/(.*) ws://api:4000/graphql/$1 [P,L]

# Serve React App (Fallback to index.html for routing)
<Directory /usr/share/nginx/html>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
FallbackResource /index.html
</Directory>
</VirtualHost>
8 changes: 1 addition & 7 deletions config/docker/setup/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,7 @@ server {
}

location /graphql {
proxy_pass http://host.docker.internal:4000/graphql/;

# Enable CORS
add_header Access-Control-Allow-Origin https://test.talawa.io;
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
add_header Access-Control-Allow-Headers "Content-Type, Authorization";
add_header Access-Control-Allow-Credentials true;
proxy_pass http://api:4000;


# Proxy headers
Expand Down
7 changes: 7 additions & 0 deletions config/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,12 @@ export default defineConfig({
host: '0.0.0.0',
// Uses PORT environment variable, defaults to 4321
port: PORT,
proxy: {
'/graphql': {
target: 'http://localhost:4000',
changeOrigin: true,
secure: false,
},
},
},
});
9 changes: 9 additions & 0 deletions docs/docs/docs/getting-started/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ If you are trying to access Talawa Admin from a remote host with the API URL con
REACT_APP_TALAWA_URL="http://YOUR-REMOTE-ADDRESS:4000/graphql"

```
:::tip Proxy Configuration
To avoid CORS issues when hosting the Admin and API on different IP addresses, you can use a **relative path** for the backend URL.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. The documentation must assume that the API and Admin apps are always running on separate IP addresses whether or not it's a Dev or Prod environment.
  2. You must assume the configuration requires IP addresses to be ALWAYS provided.
  3. Your approach is limited to the software developer perspective and not the end user who will be deploying this on distributed systems.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated the documentation to reflect the distributed system perspective, clarifying that the Web Server must be configured to proxy traffic to the API IP.

Talawa-Admin includes a pre-configured Reverse Proxy (via Vite in Dev, and Nginx/Apache in Prod).

**Recommended Configuration:**
```bash
REACT_APP_TALAWA_URL=/graphql
REACT_APP_BACKEND_WEBSOCKET_URL=/graphql
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear in the documentation how the configuration needs to be updated when the app runs:

  1. With Docker
  2. Without Docker

You need to add examples for all the following cases:

  1. Docker
    1. API and Admin run on local host
    2. API and Admin run on different systems
  2. Non Docker
    1. API and Admin run on local host
    2. API and Admin run on different systems


#### Setting up REACT_APP_BACKEND_WEBSOCKET_URL in .env file

Expand Down
Loading