0.1.10 • Published 2 months ago

@lrnzdms/local-server v0.1.10

Weekly downloads
-
License
-
Repository
github
Last release
2 months ago

Local Server

A light local http server with proxy capabilities.

import { DevServer } from '@lrnzdms/local-server';
  
const options = {
  
  // Port on localhost. Optional. Default 3000
  port: 3000,
  
  // The directory to serve. Optional. Default "."
  root: ".",
  
  // Hot reload. Optional. Default true
  hot: true,

  // Listen to WebSocket messages to trigger updates. Optional. Default false
  listenToWS: false,

  // Port of another server to notify via WebSocket on updates. Optional
  notifyPort: 8081,

  // Routes to proxy. Order matters: 
  // The first matched route will be followed
  proxies: [
    {
      // The relative route to catch.
      route: "/foo",

      // The url to proxy the route to.
      target: "http://example.com",

      // Optional. A modifier function to change the route of the target.
      urlModifier: (url: string) => url.replace("foo", "bar"),
      
      // Optional. Set of headers to inject into the request
      headers: { 
        ["header-key"]: "header-value" 
      }
    }
  ]
}

// Creates and starts the server on http://localhost:port
const server = new DevServer(options);

// Triggers the hot reload
server.update();

// E.g. usage with esbuild:
esbuild.build({
  [...]
  watch: {
    onRebuild(err) {
      server.update();
    },
  }
})
0.1.10

2 months ago

0.1.8

8 months ago

0.1.7

8 months ago

0.1.9

8 months ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago

0.0.1

1 year ago