Skip to content

Fetching data from an unsecure HTTP resource and configuring my back-end for deployment

0

For better context, here's a link to branch for deployment in my project repository.

I built a weather app in React + Vite that fetches city data from an unsecure HTTP resource, as seen in the SearchCity.tsx file. However, when I published my app to Amplify, the app can't fetch data from the resource due to cross-protocol policies. I tried implementing a proxy server in my app.js file to handle the data being fetched, but it didn't work. I think it's most likely because the app.js file in my back-end lib directory is not being recognized during deployment. I tried implementing this deploy-manifest.json file to set the lib directory as the app's backend, but still no luck.

Can anyone tell me how I could properly configure the back-end so it can recognized when I publish to Amplify? Or other ways my app could fetch data from an HTTP resource if possible? Also, could anyone take a look at my repository to see if anything else looks incorrect?

asked 2 years ago194 views

2 Answers
0

Is your Amplify site using HTTPS? If yes, it is not possible for a HTTPS site to request HTTP content because of mixed content security policy.

You can implement HTTPS proxy to fetch HTTP content. Your proxy code looks OK. I am not much of a Node developer, so apologies if my comments are incorrect.

I noticed that any request to http://api.geonames.org/ gets redirect to https://api.geonames.org which currently does not have a properly SSL/TLS cert installed. Can your configure your web request code to ignore cert error?

This may help

const options = { rejectUnauthorized: false };   // ignore cert error
url = "https://api.geonames.org/";
https.get(url, options);
AWS
EXPERT

answered 2 years ago

  • Unfortunately it did not help, and I'm still not sure whether my lib backend is being recognized or not.

  • You will have to configure backend API as suggested by Leon

0

Hi, It appears that you are hosting an SSG app using Amplify host and require a backend API to request data. Please note that Amplify does not provide servers for hosting your backend API (such as Express) unless you are hosting an SSR app like Next.js app from the Amplify console. In your case, I recommend using the Amplify REST API serverless solution (APIGateway + Lambda function). For more information, please refer to this documentation.

AWS
SUPPORT ENGINEER

answered 2 years ago

  • I will implement this, but I might have to use a different API

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.