跳至內容

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?

已提問 2 年前檢視次數 198 次

2 個答案
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
專家

已回答 2 年前

  • 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
支援工程師

已回答 2 年前

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

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。