Httprelay Proxy Hello World example
by Jonas Jasas
HTML
<h1>Proxy Hello World</h1>
<h2><a href="https://httprelay.io/" target="_blank">HTTP Relay</a> proxy communication method</h2>
<p>
This is the most basic example of the <strong>client to client as a server</strong> communication method.
</p>
<p>
Copy this link and paste it in to the new browser tab to see the result:
<div id="serverLink" href="" target="_blank">
<span class="proxy-url" id ="proxyUrl"></span><span class="proxy-server" id="proxyServer"></span><span class="proxy-path" id ="proxyPath"></span>
</div>
</p>
<details>
<summary>URL legend</summary>
<ul>
<li class="proxy-url">URL of HTTP Relay proxy communication method</li>
<li class="proxy-server">Server name</li>
<li class="proxy-path">Path</li>
</ul>
</details>
CSS
.proxy-url {
color: blue;
}
.proxy-server {
color: green;
}
.proxy-path {
color: red;
}
TypeScript
//import Httprelay from 'https://cdn.httprelay.io/httprelay-proxy-v1.js'
import Httprelay from 'https://www-namai.jon.lt/httprelay/public/httprelay'
// Creating random name server
let httprelay = new Httprelay()
// Registering handler for the path
httprelay.get('/hello', () => `Hello from your browser: ${navigator.appVersion}!`)
// Starting server
httprelay.start()
// NOT IMPORTANT ///////////////////////////////////////////////////////////////////////////////
document.getElementById('proxyUrl').innerHTML = httprelay.proxyUrl + '/';
document.getElementById('proxyServer').innerHTML = httprelay.serverId;
document.getElementById('proxyPath').innerHTML = httprelay.routes[0].path;