"html/main.html: not found" kdb 网络应用程序出错
"html/main.html: not found" error in kdb web application
我正在参考 https://code.kx.com/v2/wp/websockets/ 使用 websocket 开发一个网络应用程序。
应用程序驻留在路径:
Directory structure:
/Users/repos/chatu/
-->html
--> main.html
--> main.js
-->q
--> main.q
q)\pwd
"/Users/repos/chatu" //- and main.html(index) is at path /Users/repos/chatu/html/main.html
当密码为“/Users/repos/chatu”时,网页可以在浏览器上正常打开 url - http://localhost:5001/main.html
但是当pwd更改为任何其他目录时,例如
q)\pwd
"/Users/repos"
然后点击与上面相同的 url 会抛出以下错误:
html/main.html: not found
我可以从错误中了解到,Web 服务器期望在当前工作目录中找到 html/main.html,但无法找到它。
How/Where 我可以为 index.html 设置绝对路径,使 Web 浏览器可以从任何当前工作目录找到 main.html 页面吗?(不能 find/understand 任何答案解决了同样的问题)。
Code snippet -
main.js
function connect(){
if ("WebSocket" in window) {
ws = new WebSocket("ws://localhost:5001/");
output.value="connecting...";
/* ws.onopen=function(e){output.innerHTML="connected"}; */
ws.onclose=function(e){output.innerHTML="disconnected"};
ws.onerror=function(e){output.value=e.data};
/*
when a message is received,
prepend the message to the display area
along with the input command
*/
} else alert("WebSockets not supported on your browser.");
}
main.html
<!doctype html>
<html>
<head>
<title>Chatu</title>
<style>
/* define some CSS styling on page elements */
div#wrap{
width:100%;
overflow:auto;
}
textarea#txtInput {width: 97.5%; height: 60px; float:left; padding: 10px; margin-top: 10px;}
div#txtOutput{
width: 97.5%; height: 300px; font-family: "Courier New"; padding: 10px;
border: 1px solid gray; margin-top: 2px; overflow:auto;
}
</style>
</head>
<body>
<div id="wrap">
<fieldset id='heads' style="border:1; border-radius:10px">
<legend align="center" style="color:blue">Chatu</legend>
<div id="txtOutput"></div>
<textarea id="txtInput" autofocus></textarea>
</fieldset>
</div>
</body>
<script type="text/javascript" src="main.js"></script>
</html>
main.q
.z.ws:{neg[.z.w].j.j @[.da.mf;x;{`$ "'",x}];};
.h.HOME是您感兴趣的变量
我相信您可以像您在 kdb 网络应用程序中描述的那样为索引 html 设置绝对路径的方法是使用 .h.HOME.
分配此路径
变量 .h.HOME 是一个包含网络服务器根位置的字符串。
如果您想了解有关 .h.HOME 的更详细说明,请参阅 https://code.kx.com/v2/ref/doth/#hhome-webserver-root
我正在参考 https://code.kx.com/v2/wp/websockets/ 使用 websocket 开发一个网络应用程序。
应用程序驻留在路径:
Directory structure:
/Users/repos/chatu/
-->html
--> main.html
--> main.js
-->q
--> main.q
q)\pwd
"/Users/repos/chatu" //- and main.html(index) is at path /Users/repos/chatu/html/main.html
当密码为“/Users/repos/chatu”时,网页可以在浏览器上正常打开 url - http://localhost:5001/main.html
但是当pwd更改为任何其他目录时,例如
q)\pwd
"/Users/repos"
然后点击与上面相同的 url 会抛出以下错误:
html/main.html: not found
我可以从错误中了解到,Web 服务器期望在当前工作目录中找到 html/main.html,但无法找到它。
How/Where 我可以为 index.html 设置绝对路径,使 Web 浏览器可以从任何当前工作目录找到 main.html 页面吗?(不能 find/understand 任何答案解决了同样的问题)。
Code snippet -
main.js
function connect(){
if ("WebSocket" in window) {
ws = new WebSocket("ws://localhost:5001/");
output.value="connecting...";
/* ws.onopen=function(e){output.innerHTML="connected"}; */
ws.onclose=function(e){output.innerHTML="disconnected"};
ws.onerror=function(e){output.value=e.data};
/*
when a message is received,
prepend the message to the display area
along with the input command
*/
} else alert("WebSockets not supported on your browser.");
}
main.html
<!doctype html>
<html>
<head>
<title>Chatu</title>
<style>
/* define some CSS styling on page elements */
div#wrap{
width:100%;
overflow:auto;
}
textarea#txtInput {width: 97.5%; height: 60px; float:left; padding: 10px; margin-top: 10px;}
div#txtOutput{
width: 97.5%; height: 300px; font-family: "Courier New"; padding: 10px;
border: 1px solid gray; margin-top: 2px; overflow:auto;
}
</style>
</head>
<body>
<div id="wrap">
<fieldset id='heads' style="border:1; border-radius:10px">
<legend align="center" style="color:blue">Chatu</legend>
<div id="txtOutput"></div>
<textarea id="txtInput" autofocus></textarea>
</fieldset>
</div>
</body>
<script type="text/javascript" src="main.js"></script>
</html>
main.q
.z.ws:{neg[.z.w].j.j @[.da.mf;x;{`$ "'",x}];};
.h.HOME是您感兴趣的变量
我相信您可以像您在 kdb 网络应用程序中描述的那样为索引 html 设置绝对路径的方法是使用 .h.HOME.
分配此路径变量 .h.HOME 是一个包含网络服务器根位置的字符串。
如果您想了解有关 .h.HOME 的更详细说明,请参阅 https://code.kx.com/v2/ref/doth/#hhome-webserver-root