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