【问题标题】:React: net::ERR_CONNECTION_REFUSED反应:net::ERR_CONNECTION_REFUSED
【发布时间】:2020-06-17 06:49:27
【问题描述】:

我已经克隆了这个项目https://github.com/LaurenceHo/react-weather-app#webpack-reactjs-and-typescript

我已正确执行所有步骤,我已在 Map Forecast API 的 https://api.windy.com/keys 此处创建了我的新密钥,并在此处作为说明输入 https://github.com/LaurenceHo/react-weather-app/blob/master/src/views/weather-map.tsx

现在我运行服务器,我得到这个方法的错误getWeather

我在我的网络和控制台中查找,这些是我可以看到的错误,但我不知道如何修复它

这是带有方法的api

export const getWeatherByTime = (
  latitude: number,
  longitude: number,
  time: number,
  exclude: string,
  units: string
): Promise<Forecast> => {
  const requestUrl =
    `${CLOUD_FUNCTION_URL}getWeather?lat=${latitude}&lon=${longitude}&time=${time}` +
    `&exclude=${encodeURIComponent(exclude)}&units=${encodeURIComponent(units)}`;
  return fetch(requestUrl)
    .then(checkStatus)
    .then(parseJSON)
    .then((data: any) => data);
};

如何解决问题?我该如何解决?

【问题讨论】:

  • 您的开发服务器是否正在运行?它正在打电话给localhost:3000...
  • 是的,它在localhost:8080 上运行,但请求已发送到localhost:3000..can,这是问题所在吗?

标签: javascript reactjs rest api fetch


【解决方案1】:

你克隆的 GitHub 项目在README.md 文件中这样说:

因为我们在做本地开发时不想使用 Google Cloud Function,所以我们编写了简单的 NodeJs Express 服务器来返回 JSON 响应。移动到 dev-server 文件夹 cd dev-server,然后运行 ​​npm i 以安装 npm 模块。之后运行npm start启动NodeJs Express Server,我们就可以进行前端开发了。

在安装 npm 包后移动到 dev-server 文件夹并执行 npm start - 似乎会在端口 3000 上启动开发服务器。

【讨论】:

    猜你喜欢
    • 2022-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-18
    • 1970-01-01
    • 2019-05-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多