Туннелирование локальных приложений через HTTPS без проброса портов
npm init -y && npm install ws
const WebSocket = require('ws');
const http = require('http');
const subdomain = process.argv[2] || 'test';
const port = process.argv[3] || 3000;
const ws = new WebSocket('wss://local.wddt.ru:3000');
ws.on('open', () => {
ws.send(JSON.stringify({ type: 'register', subdomain }));
console.log(`Туннель: https://${subdomain}.local.wddt.ru -> localhost:${port}`);
});
ws.on('message', (data) => {
const msg = JSON.parse(data);
if (msg.type === 'request') {
const options = {
hostname: 'localhost',
port: port,
path: msg.url,
method: msg.method,
headers: msg.headers
};
const req = http.request(options, (res) => {
let body = Buffer.alloc(0);
res.on('data', chunk => body = Buffer.concat([body, chunk]));
res.on('end', () => {
ws.send(JSON.stringify({
type: 'response',
requestId: msg.requestId,
status: res.statusCode,
headers: res.headers,
body: body.toString('base64')
}));
});
});
req.on('error', () => {
ws.send(JSON.stringify({
type: 'response',
requestId: msg.requestId,
status: 502,
body: Buffer.from('Service unavailable').toString('base64')
}));
});
if (msg.body) req.write(Buffer.from(msg.body, 'base64'));
req.end();
}
});
node client.js myapp 3000
Ваше приложение станет доступно: https://myapp.local.wddt.ru
node client.js react 5173
→ https://react.local.wddt.ru
node client.js api 3001
→ https://api.local.wddt.ru
node client.js static 8080
→ https://static.local.wddt.ru
node client.js python 5000
→ https://python.local.wddt.ru
nohup node client.js myapp 3000 > tunnel.log 2>&1 &
node client.js frontend 3000 &
node client.js backend 3001 &
node client.js admin 3002 &
pkill -f "node client.js"
Ваше приложение работает на localhost:порт
Клиент подключается к серверу и проксирует запросы
Приложение доступно через HTTPS поддомен