LocalProtocol

Protocol handler that proxies requests to localhost servers.

Protocol handler that proxies requests to localhost servers.

Forwards requests to local development servers for hot-reloading workflows. Features response caching and 304 Not Modified support.

View source ↗

Constructor

new LocalProtocol(hosts: Record<string, string>);

Prop

Type

Methods

Prop

Type

Examples

const protocol = new LocalProtocol({
  myapp: 'http://localhost:3000',
  api: 'http://localhost:8080',
});

// This proxies to http://localhost:3000/index.html
const response = await protocol.handle('get', 'app://myapp/index.html');

constructor

const protocol = new LocalProtocol({
  myapp: 'http://localhost:3000',
  api: 'http://localhost:8080',
});

handle

// Proxies to http://localhost:3000/api/data?foo=bar
const response = await protocol.handle('get', 'app://myapp/api/data?foo=bar');
console.log(response.status);
// POST with headers
const response = await protocol.handle('post', 'app://api/submit', {
  'Content-Type': 'application/json',
});

On this page