Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

http-bundle

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http-bundle

Generic http handler for generated bundles

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

http-bundle

Build Status NPM

Generic node.js HTTP handler for generated bundles

This is great for serving browserify bundles, generated css, or any other content that is generated infrequently. It automatically gzips the result and implements ETag caching.

example

var bundle = require('http-bundle');
var http = require('http');

var b = bundle({
    compile: compile,
    type: 'text/css'
});

var server = http.createServer(b);
server.listen(8000);

function compile(cb) {
    // usually a more elaborate compilation process
    cb(null, '.css { content: "some css"; }');
}

api

http-bundle(opts)

Returns an HTTP handler function that serves the bundle when requested. The returned function can be used as Express/Connect middleware or as a normal HTTP server handler function.

The compile function is required to be specified in the opts object. It will be called as compile(opts, callback) to generate the bundle the first time it is requested. The opts object is the same as the opts passed to the http-bundle function.

Inside the compile function you can call this.invalidate() to force the bundle to be recompiled the next time it is requested. Usually you want to save this function and call it later (for example from a file watcher).

options

  • compile: The function that will be called when the bundle is first requested. It must call the callback with an optional error and the result.
  • type: (optional) A string specifying the Content-Type to set on the result.

Keywords

bundle

FAQs

Package last updated on 06 Aug 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts