简体   繁体   English

如何在 Vercel Next.js 上运行 http 请求

[英]How to run http request on Vercel Next.js

I am using React.js, Nextjs and Vercel for my application and when I have a function that runs a http quest on my backend server.我在我的应用程序中使用 React.js、Nextjs 和 Vercel,当我有一个 function 在我的后端服务器上运行 http 请求时。

fetch(`http://10.10.10:8080/api/test`)
            .then((res) => res.json())
            .then((data) => {})

This works perfectly fine locally but when i push it to github and successfully build in Vercel and when i test it out, it throws an error:这在本地工作得很好,但是当我将它推送到 github 并在 Vercel 中成功构建时,当我对其进行测试时,它会引发错误:

was loaded over HTTPS, but requested an insecure resource 'http://10.10.10:8080/api/test'. This request has been blocked; the content must be served over HTTPS

Is there no way to run http requests on vercel?有没有办法在 vercel 上运行 http 请求? so does it has to be https?那么它必须是 https 吗?

If you want to call the API side of next from the front side just do:如果您想从前面调用 next 的 API 侧,只需执行以下操作:

fetch(`/api/test`)
  .then((res) => res.json())
  .then((data) => {})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM