node package manager
Loosely couple your services. Use Orgs to version and reuse your code. Create a free org »

brick-server

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