Software⏱️ 2 min read📅 2026-05-30

How to Fix: NestJS Swagger UI loads on real Android device but "Try it out" fails with CORS / Failed to fetch

NestJS Swagger UI loads on real Android device but fails with CORS / Failed to fetch due to backend IP address not being accessible from the device's network.

Quick Answer: Check if the Android device is connected to the same Wi-Fi network as the MacBook and update the backend IP address in the Swagger UI configuration to use the device's IP address instead of the MacBook's.

The issue you're experiencing is due to the Android device's CORS policy blocking the requests from the Swagger UI. When you click on a 'Try it out' button, it makes an HTTP request to your backend server, but since the request is coming from a different domain (the Swagger UI), the browser doesn't allow it by default.

🚀 How to Resolve This Issue

Method 1: Enable CORS on Your Backend Server

  1. Step 1: In your NestJS application, add the `@nestjs/common` module and import it in your main application module.

Method 2: Configure CORS on Your Backend Server

  1. Step 1: Create a new file named `cors.config.ts` in your project's root directory.

🎯 Final Words

By enabling CORS on your backend server, you should be able to resolve the 'Try it out' issue and test your endpoints successfully.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions