swagger-api / swagger-api/swagger-ui

CORS Error When Accessing Swagger API Deployed on AWS EC2

Open
#10,107 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
29k
Forks
9.3k
Avg merge
2d 23h
Merged PRs (30d)
25

Description

I have deployed a NestJS backend on an AWS EC2 instance. The Swagger UI is accessible, but when I try to hit the API using Swagger, I receive the following error:

ISSUE: Failed to fetch. Possible Reasons:

  1. CORS
  2. Network Failure
  3. URL Scheme must be "http" or "https" for CORS request.

Details:
The API works correctly when tested directly on the EC2 instance (e.g., using curl).
The Swagger UI is accessed via the public IP address of the EC2 instance.
The error occurs when trying to access the API endpoint through the Swagger UI.
My backend is running on http://localhost:3033, and the Swagger UI is being accessed via the public IP of the EC2 instance.

Troubleshooting Steps Taken:
Confirmed that the backend API is accessible directly from the EC2 instance.
Verified that the server is configured to handle CORS requests by setting the appropriate CORS headers in the NestJS application.
Checked the network configurations and security groups in AWS EC2 to ensure proper access.

Environment:
NestJS version:
AWS EC2 Instance: Amazon linus(t2.micor).
Swagger version: 6.0.5
Browser: Chrome, Edge
Node.js version: Latest
CORE: 9.0.0

Request URL: http://localhost:3033/api/v1/auth/signin

Screenshot: -

Error Image

Question:
How can I resolve this CORS issue, and what configurations are required to allow the Swagger UI to make successful API requests in this setup?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The payload names no repository file, test, or code entry point; begin by locating the Swagger UI request configuration and the deployed API URL used by the OpenAPI document. A contribution would need a reproducible repository change and a test or documented verification, neither of which this issue currently specifies.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, javascript, node.js
Domain
api, backend, cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
15/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.