我正在使用 React 前端和 Node.js 后端(API)构建 Web 应用程序。
在 React 前端,我调用这样的 API 方法:
axios({
method: 'post',
url: 'http://servername:9999/reports.activities',
data: {
user_id: 1
}
}).then(res => {
this.setState(res.data);
});
Run Code Online (Sandbox Code Playgroud)
有时我需要测试尚未发布到生产环境的 API 方法。
当我在本地测试后端时,我nodemon api.js在localhost:9999.
每次我想用本地运行的 API 测试前端时,我都http://servername:9999必须http://localhost:9999在我的前端代码中更改为。
我认为这不是正确的方法。
使用不同 url 进行开发(在npm start本地运行时)和生产(npm build)的最佳方法是什么?
我正在考虑为此目的使用dotenv。这是正确的方法吗?
最佳做法是什么?
我按照本教程安排了使用节点运行脚本的任务:
https://eddyerburgh.me/run-a-node-script-with-windows-task-scheduler
我让我的电脑打开,以便它可以执行脚本,但是当我查看它是否确实执行时,只有一个 cmd.exe 实例打开并且任务没有执行脚本。
这是我配置操作的方式:
Program/Script - C:\WINDOWS\system32\cmd.exe
Arguments - --a -i -c "cd C:\Users\xxxxx\Desktop\folder; node script.js"
Run Code Online (Sandbox Code Playgroud)
还有另一种方法吗?