npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@clocklimited/cf-api

v3.1.1

Published

A pluggable JSON API server

Downloads

106

Readme

cf-api

A pluggable JSON API server

This is CatfishApi but without all of the bloat and a simple API to register plugins. Everything becomes a plugin.

Installation

npm install --save cf-api

Usage

var createApi = require('cf-api')

var api = createApi(options)
  server = api.initialize()

server.get('/', homepage)
server.post('/form', submit)

// This tells the api that you've finished adding your routes
// and you now want it to add the error handling middleware
server.emit('preBoot')

server.listen(port)

API API

var api = createApi(Object: options)

Create an API instance. There are options available:

  • checkOrigin - a function with the signature function (url, cb) {} to check req.headers.origin. cb(null, true) to allow and origin, cb(null, false) to deny an origin. Defaults to cb(null, true) for all requests, meaning all cross-domain requests are allowed. It is up to the user to implement their whitelist/blacklist.
  • logger - a logger object with methods debug(), info(), warn() and error() (default: console).
  • maxBodySize - an option to be passed along to the body-parser json middleware function. If this is a number it will be the number of bytes, otherwise it will be parsed by the bytes module (default: undefined which falls back to the body parser default of '100kB').
  • initialMiddleware - an Express middleware function that will be used before all other middleware. Useful for Sentry error handlers.
  • corsOptions - an object with the following keys:
    • exposeHeaders - sets Access-Control-Expose-Headers

For backwards compatibility, the allowedDomains option still works and generates a checkOrigin function for you.

api.initialize()

Create and return the server.

Changelog

3.1.1

  • Cors header Access-Control-Allow-Credentials is now set to true

3.1.0

  • mis-tagged commit from unpulled work, unpublished.

3.0.0

  • express is now installed as a peer dependency

2.6.0

  • Allow setting cors options through initialisation options.

2.0.0

  • Plugin interface now totally removed. Application components are registered outside of the scope of this module.
  • User must call server.emit('preBoot') after all routes have been added to make tell the api to add the last piece of middleware: the error handler. This is due to a change in Express 4.

1.1.0

  • API now allows binary request bodies as well as json

1.0.1

  • Fixed cors middleware not terminating preflight requests. Do not use 1.0.0, please upgrade.

1.0.0

  • Added checkOrigin option in place of allowedDomains. Latter is still supported for compatibility.

Pre 1.0.0

  • Unstable!

Credits

Built by developers at Clock.

Licence

Licensed under the New BSD License