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

alchemy-router

v1.0.4

Published

alchemy-router is the gateway from HTTP to Alchemy Resources for the Alchemy Micro-services Framework

Downloads

12

Readme

Alchemy Router

npm version Build Status License

Alchemy Router is the gateway from HTTP to Alchemy Resources for the Alchemy Micro-services Framework. It can be used directly as an application or as a library to build and customise using express middleware and routes.

Router Application

To install the alchemy router run:

npm install -g alchemy-router

Then execute:

alchemy-router

You can configure the router with the environment variables:

  1. AMQP_URI default 'amqp://localhost': the location of the (RabbitMQ) AMQP server
  2. PORT default 8080: the port to open the HTTP server on
  3. TIMEOUT default 5000: the router will return a 408 timeout response after waiting for the service.
  4. PATHS default '{}': the JSON string that matches service queues directly with paths, e.g. PATHS='{"/hello" : 'service.hello'}' will direct all calls that start with path /hello to the queue service.hello.

Docker

This repository also comes with an example Docker container, which is published to the docker hub.

Build the Docker container with:

docker build -t alchemy-router:$VERSION .

Push the docker container with:

docker push alchemy-router:$VERSION

Router Library

To install the router as a library:

npm install alchemy-router

To start a router:

AlchemyRouter = require 'alchemy-router'
router = new AlchemyRouter()
router.start()

Middleware

Middleware can be used to extend the routers with custom functionality. Middleware are objects with a callback that is an express middleware callback function, an optional start and stop functions that can control the life cycle of the middleware.

logging_middleware = {
  callback: (req, res, next) ->
    console.log req.path
    next()

  # promise to start middleware
  start: -> true

  # promise to stop middleware
  stop: -> true
}

AlchemyRouter = require 'alchemy-router'
router = new AlchemyRouter()
router.start({
  middleware: [logging_middleware]
})

Additional Routes

Additional hard-coded routes can be added to the router, these can be useful for health-checks, logging, versioning ... Note: these routes will override any service routes.

hello_route = (app) ->
  app.get '/hello', (req, res) =>
    res.send {say: "hello"}
    res.end()

AlchemyRouter = require 'alchemy-router'
router = new AlchemyRouter()
router.start({
  additional_routes: [hello_route]
})

Notes

The Router will not override any provided x-interaction-id headers, and will generate the header with a UUID if not present. This is to preserve traceability when calling between different platforms. If you require Interaction IDs to be unique within your platform, you may wish to extend the Router with a piece of middleware that generates your own Interaction IDs.

Documentation

This Alchemy-Router documentation is generated with docco from its annotated source code.

The Alchemy-Router package exports Router:

module.exports = require("./router")

Examples