Skip to content

Latest commit

 

History

History
41 lines (30 loc) · 1.01 KB

serve.md

File metadata and controls

41 lines (30 loc) · 1.01 KB

serve export

🔝 REserve documentation

REserve's main entry point is serve.

interface Server {
  on (eventName: ServerEventName, listener: ServerListener)
  close: () => Promise<void>
}

function serve (configuration: Configuration): Server

Types definition for serve

The configuration must comply with the properties and mappings documented here.

The server object implements an interface that mimics the EventEmitter::on method and, during execution, it triggers events with parameters to notify any listener of its activity.

import { serve } from 'reserve'

const server = serve({
  "port": 8080,
  "mappings": [{
    "match": "^/private/",
    "status": 403
  }, {
    "match": "^/(.*)",
    "file": "./$1"
  }, {
    "status": 404
  }]
})

server.on('ready', ({ url }) => console.log(`Server running at ${url}`))

Example of a server using the serve function