Report this

What is the reason for this report?

How to connect a Droplet hosting a site to an app hosting an API

Posted on July 13, 2021

I have a DO app with a react application. This application connects to my DO Droplet to retrieve some search results.

When I attempt to connect from my development environment the Droplet, it returns data and the locally deployed react app displays the data.

However, when I deploy the react app onto the Droplet I receive the error: Unhandled Rejection (TypeError): Not allowed to request resource

This originates in the applications request to the API hosted on the droplet. I have attempted both the public IP for the droplet as well as the private IP. The same issue occurrs once the application is deployed on the DO app.

What areas can I look at where there might be an issue?

const fetchReferences = async () => {

fetch(‘http://xxx.xxx.xxx.xxx:8080/search/’, {. //this is the line that errors. method: ‘POST’, body: JSON.stringify({ url: searchState.searchCriteria



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hello,

As far as I can see, you have the CORS configured correctly, however if your frontend app is loading via HTTPS you would need to set up your backend service via HTTPS as well.

You could do that by using Nginx as a reverse proxy and then installing a free Let’s Encrypt SSL certificate as per the instructions here:

https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-20-04

Regards, Bobby

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.