API基础网址在Reactjs登录模块中不起作用。

huangapple go评论65阅读模式
英文:

API base url not working in Reactjs login module

问题

我正在使用Reactjs,我从服务器上下载了项目,现在尝试运行这个项目,但是我现在无法登录(输入了正确的详细信息),但问题出在“API URL”上,我在控制台中检查了一下,在生产服务器上的Api URL是 https://xxxxxxxxxx.com/api/login/,但在本地主机控制台中显示如下

主机
	localhost:3001
文件名
	/undefined/login/

那么我该如何让这个工作起来?这是我当前在“src/utlis/api.js”中的代码:

export const BASE_URL = `${process.env.REACT_APP_API_BASE_URL}`
axios.defaults.baseURL = BASE_URL
英文:

I am working with Reactjs,I downloaded project from server and now trying to run this project,But right now i am unable to login( entered correct details) but problem is with "API URL",I checked in console,Api url for live server is "https://xxxxxxxxxx.com/api/login/" but in localhost console displaying like

host
	localhost:3001
filename
	/undefined/login/

So how can i make this working ? Here is my current code in "src/utlis/api.js"

export const BASE_URL = `${process.env.REACT_APP_API_BASE_URL}`
axios.defaults.baseURL = BASE_URL

答案1

得分: 1

创建一个名为.env的文件,放在项目文件夹内。

然后将以下内容写入该文件。

REACT_APP_API_BASE_URL=https://xxxxxxxxxx.com/api/

欲了解更详细信息,您可以查看以下链接。

英文:

Create a file named .env inside the project folder.

And write the following to this file.

REACT_APP_API_BASE_URL=https://xxxxxxxxxx.com/api/

For more detailed information, you can check the following.

huangapple
  • 本文由 发表于 2023年1月6日 14:44:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/75027777.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定