Question

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

Posted July 13, 2021 142 views
ReactDigitalOcean App PlatformDigitalOcean Droplets

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

2 comments

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.

×
Submit an Answer
1 answer

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

by Brian Boucheron
Let's Encrypt is a Certificate Authority (CA) that provides an easy way to obtain and install free TLS/SSL certificates, thereby enabling encrypted HTTPS on web servers. It simplifies the process by providing a software client, Certbot, that attempts to automate most (if not all) of the required steps. In this tutorial, you will use Certbot to obtain a free SSL certificate for Nginx on Ubuntu 20.04, and set up your certificate to renew automatically.