The service allows forward HTTP requests into local machine port initiated by client and send responses back.
npm install
npm start
import { forward } from '@signageos/forward-server-bridge/dist/client';
const { publicUrl, stop } = await forward({
localPort: 9080, // Required. Port where the public traffic will be forwarded to.
serverUrl: 'https://localhost:8080', // Required. Public URL (including scheme & port) of the forward server.
localHostname: 'localhost', // Optional. Hostname where the public traffic will be forwarded to. Default: 'localhost'.
});
console.log(`You can access the forwarded server on ${publicUrl}`);
await stop(); // Stop forwarding.
Once the client forward is established, the server accepts HTTP requests on returned publicUrl
and forwards them to the localPort
on the localHostname
.
The logic creates the WebSocket tunnel under the hood initiated from client side to the serverUrl
. So it can be called even from a computer that has firewall on incoming connections.
sequenceDiagram
participant PublicUser
participant ForwardingServer
participant LocalClient
Note right of LocalClient: Local machine initiates the forwarding
LocalClient->>ForwardingServer: Establish WebSocket tunnel
Note left of ForwardingServer: Publicly accessible "publicUrl" endpoint.<br> E.g.: `http://forward.example.com/43fea3c24/`
PublicUser->>ForwardingServer: Forward request
Note right of ForwardingServer: "serverPort" is listening
ForwardingServer->>LocalClient: Forward request
Note right of LocalClient: "localPort" is listening
Note right of LocalClient: Optionally "localHostname" is listening
LocalClient->>ForwardingServer: Forward response
ForwardingServer->>PublicUser: Forward response
This feature can be used to allow some local service to be accessible from the internet. Even if the local machine doesn't have public interface (hidden in private network behind the router). Only the forward server needs to be accessible publicly from the internet.