简体   繁体   English

Api 仅适用于本地主机

[英]Api works only on localhost

on my machine i get a json response when i consume my api and eveything is working fine , but the weird thing is my api not giving me data when i upload it online , i am using namecheap shared hosting , this is the result i get when try to consume api在我的机器上,当我使用我的 api 并且一切工作正常时,我得到一个 json 响应,但奇怪的是我的 api 在我在线上传时没有给我数据,我使用的是 namecheap 共享主机,这是我得到的结果尝试消费api

在此处输入图像描述

this is my index.js code这是我的 index.js 代码

app.get("/project/index/login", (req, res) => {   (async () => {
    try {
      await client.login();
      res.send("Login successful!");
    } catch (err) {
      res.send("Login failed!");
    }   })(); });


app.get("/project/index/user/:id", (req, res) => {  
 const id = req.params.id;   (async () => {
    try{
      const data = await client.getInfo({ id: id })
      res.json(data.data);
    }catch(error){
      res.send(error);

    }
   

  })(); });

It's probably because your API server is running only on localhost.这可能是因为您的 API 服务器仅在 localhost 上运行。 Check your API server!.检查您的 API 服务器! You must run the API server which has a domain.您必须运行具有域的 API 服务器。

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

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