Question

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

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

Show comments

Submit an answer

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!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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