[英]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.