Я разрабатываю веб-приложение, используя websocket, взяв ссылку из https://code.kx.com/v2/wp/websockets/.
Приложение находится по пути:
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
Когда pwd равен "/ Users/ repos / chatu ", то веб-страница правильно открывается в браузере, используя url - http://localhost:5001/main.html
Но когда pwd изменяется на любой другой каталог, такой как
q)\pwd
"/Users/repos"
Тогданажатие на ту же ссылку, что и выше, приводит к появлению ошибки ниже:
html/main.html: not found
Что я могу понять из этой ошибки, так это то, что веб-сервер ожидает html / main.html в текущем рабочем каталоге и не может найти.
Как / Где я могу установить абсолютный путь для index.html, чтобы из любого текущего рабочего каталога веб-браузер мог найти страницу main.html? (Не удается найти / понять ни один ответ, который решает ту же проблему).
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}];};