brick-server

1.0.0 • Public • Published

brick-server

NPM version build status Test coverage Downloads js-standard-style

Create an http handler for brick-router. Sends out ndjson events. Works well with opnr and garnish.

Installation

$ npm install brick-server

Usage

const brickRouter = require('brick-router')
const brickServer = require('brick-server')
const http = require('http')
 
const router = brickRouter()
 
// streams
router.on('/index.html', (cb) => {
  const loc = path.join(__dirname, 'index.html')
  const stream = fs.createReadStream(loc)
  cb(null, stream)
})
 
// strings
router.on('/index.css', (cb) => {
  const css = `
    .foo {
      color: blue;
    }
  `
  cb(null, css)
})
 
const handler = brickServer(router.match)
const server = http.createServer(handler)
server.listen(1337)

See Also

  • brick-router - modular router for serving static assets
  • opnr - launches the browser when ndjson criteria is met
  • garnish - prettifies ndjson from wzrd and similar tools

License

MIT

Package Sidebar

Install

npm i brick-server

Weekly Downloads

1

Version

1.0.0

License

MIT

Last publish

Collaborators

  • yoshuawuyts
  • hughsk