Skip to content
← Public packages

@tannerlinsley/react-summit-talk

Use TanStack: an animated React Summit talk about AI, user trust, and open-source foundations.

FollowFork

Files

localhost-only.cjs

14 lines · 643 B · JavaScript
// Restrict the HyperFrames presenter's Node server to this computer.
const net = require('node:net');
const listen = net.Server.prototype.listen;
net.Server.prototype.listen = function (...args) {
  if (typeof args[0] === 'object' && args[0] !== null) {
    if (args[0].path) throw new Error('Only localhost TCP listeners are supported');
    args[0] = { ...args[0], host: '127.0.0.1' };
  } else {
    if (typeof args[0] !== 'number') throw new Error('Only localhost TCP listeners are supported');
    if (typeof args[1] === 'string') args[1] = '127.0.0.1';
    else args.splice(1, 0, '127.0.0.1');
  }
  return listen.apply(this, args);
};