簡體   English   中英

如何從index.html對dockerized express服務器進行http調用?

[英]How to make a http call to dockerized express server from index.html?

我不明白如何從index.html進行http調用,以表示服務於該index.html的服務器,該服務器位於docker容器內。

index.html:
<script type="text/javascript">
      var getAppId = new XMLHttpRequest();
      getAppId.open("GET", "/appId", false);
      getAppId.send(null);
</script>

我需要該http調用來了解docker env變量提供的應用程序ID。 該調用必須在server.js(express.js)中進行監聽:

router.get("/appId",(req,res) => {
  res.send({applicationId : process.env.APP_ID});
});

但是,當我運行dockerized應用程序時,我看到我的http呼叫收到404 http代碼。 請幫忙!

我會使用提取:

fetch('www.example.com/appId', {
    method: 'GET',
    credentials: 'include',
    headers: { "Content-Type": "application/json"}
}).then(function(res) {
    return res.json();
    }).then(function(res){
        if(res){
           doSomesthing();
        }
        else{
            console.log('yourError')
        }
    }).catch((e)=>{console.log(e)})

但是404表示找不到路由。 您確定服務器上的所有設置都正確嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM