New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

compiled-files

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

compiled-files

statically serve compiled files with gzip & cache

  • 0.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-85.71%
Maintainers
1
Weekly downloads
 
Created
Source

compiled-files

build status NPM version Coverage Status gemnasium Dependency Status Davis Dependency status

statically serve compiled files with gzip & cache

Example

CompiledFiles will generate a route handler that serves a file including running it through a custom compilation step, optional caching and optional gzipping.

var CompiledFiles = require("compiled-files")
var resolve = require("resolve")
var path = require("path")
var url = require("url")
var browserify = require("browserify")
var http = require("http")

var ServeBrowserify = CompiledFiles({
    // custom function to take the Request and 'parse' what
    // resource the HTTP client has asked for.
    // This function finds the last part so `/js/foo` returns
    // `$opts.root/foo`
    findResource: function findResource(req, res, opts) {
        var pathname = url.parse(req.url).pathname
        var parts = pathname.split("/")
        return path.join(opts.root, parts[parts.length - 1])
    },
    // A custom compilation function. The notion is that you
    // are serving files that have a compilation step
    // here you just take the location returned from findResource
    // and return a string to the callback
    compile: function (location, opts, callback) {
        resolve(location, function (err, fileUri) {
            if (err) {
                return callback(err)
            }

            var b = browserify([fileUri])
            b.bundle(opts, callback)
        })
    },
    contentType: "application/json"
})

/* The ServeBrowserify that is returned is a function that takes
  options (which are passed to findResource & compile). It also
  takes default options like `cache` and `gzip` used to enable
  HTTP/compilation caching and gzipping support.
*/

http.createServer(ServeBrowserify({
    cache: true,
    gzip: true,
    root: path.join(__dirname, "scripts")
}))

Installation

npm install compiled-files

Contributors

  • Raynos

MIT Licenced

FAQs

Package last updated on 13 Jun 2013

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc