开发者社区> 镜像站> NPM> brick-server
brick-server
Create an http handler for brick-router
Last updated 6 years ago by yoshuawuyts .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install brick-server 
SYNC missed versions from official npm registry.

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

Current Tags

  • 1.0.0                                ...           latest (6 years ago)

1 Versions

  • 1.0.0                                ...           6 years ago
Maintainers (2)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (3)
Dependents (1)