【问题标题】:Postman api url not working after depolyment部署后 Postman api url 不起作用
【发布时间】:2023-01-03 04:06:22
【问题描述】:

我是 Web 开发的新手,最近学习了一些教程,现在我在尝试将 Next App 部署到 Vercel 后遇到了问题。

我的一个错误发生在 api url 上

在我将我的应用程序部署到 Vercel 之前,我使用的是 localhost3000 并且 api url 在邮递员处工作正常

const BASE_URL = "http://localhost:3000"

export const getUsers = async () => {
    // declar response and assign fetch data
    const response = await fetch(`${BASE_URL}/api/users`)
    // declar json and assign jsoned response
    const json = await response.json()
    return json;
}

将我的应用程序部署到 Vercel 后,会提供一个新域

让 newURL = "https://crud-employee-management.vercel.app/"

就我而言,是否需要将 BASE_URL 切换为 newURL?但是在 Postman 中,newURL 不像“https://crud-employee-management.vercel.app/api/users”那样工作

我该如何修复它并在网站上使用它?

谢谢

斯坦

【问题讨论】:

  • 您确实需要将 baseUrl 切换为 newUrl。通过邮递员访问新的 url 端点时遇到什么问题?
  • 我的邮递员返回 { "error": "Error in the Connection" } 好像是从mongodb atlas连接?
  • 我觉得把我的github项目代码展示一下会更好,供大家参考:github.com/Stanlpm/CRUD-Employee-Management.git
  • Vercel 函数日志显示什么?

标签: next.js postman vercel


【解决方案1】:

你应该使用这个 URL;我的意思是没有结束斜线。 https://crud-employee-management.vercel.app

【讨论】:

    猜你喜欢
    • 2022-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-08
    • 1970-01-01
    • 2019-05-12
    • 2019-06-15
    • 1970-01-01
    相关资源
    最近更新 更多