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

dev-gateway

v0.3.0

Published

Local development cluster with now path aliases syntax support. Allows running multiple microservices as one solid server.

Downloads

5

Readme

dev-gateway

Local development cluster with now path aliases syntax support. Allows running multiple microservices as one solid server.

Build Status XO code style Greenkeeper badge

Installation

npm install --save-dev dev-gateway
# or
yarn add -D dev-gateway

Usage

At first, you need to create app.js file and define configuration:

module.exports = {
  port: 3000,
  host: 'localhost',
  rules: [{
    slug: 'auth',
    pathname: '/api/auth/**',
    dest: 'auth.api.localhost',
    run: 'micro index.js',
    cwd: './auth',
    env: {
      SECRET_TOKEN: 'kittens'
    },
    debug: true
  }, {
    slug: 'accounts',
    pathname: '/api/accounts',
    dest: 'accounts.api.localhost',
    method: ['GET', 'POST'],
    run: 'cd ./accounts && micro index.js',
    debug: true
  }, {
    pathname: '/api/entries/*',
    dest: 'entries.api.localhost',
    run: 'cd ./entries && micro index.js',
    debug: true
  }, {
    pathname: '/proxy',
    dest: 'proxy.api.localhost',
    proxy: 'https://first.pong.world/any/path'
  }]
}

The next step is to add a new script to your package.json:

{
  "scripts": {
    "dev": "dev-gateway serve app.js"
  }
}

Then run:

npm run dev

Rules

Rules access the following parametres:

  • slug - slug, just a name of rule
  • pathname - pathname alias; has similar wildcard syntax to this one now path aliases
  • dest - destination host. Microservice will be available if you send request directly to the host.
  • method - string or array. To specify allowed methods.
  • run - shell command to run your microservice.
  • port - port used by microservice. Gateway will try to detect opened port if these parametres are not defined.
  • proxy - url. All requests will be proxied to this url if parameter is defined.
  • debug - boolean or object ({ stdout: false, stderr: true}). Gateway will pipe microservice output to the terminal, if 'debug' is true.
  • env - the parameter is used to define environment variables for a microservice.
  • logFile - will pipe stdout and stderr to a specified file.
  • cwd - rule's working directory
  • maxGetPortAttempts - number of attempts to obtain a rule's port. Each attempt waits for 1 second. E.g. set maxGetPortAttempts to 30 to wait for 30 seconds before a rule is marked as "not available". Defaults to 10.
  • startTimeout - timeout (in ms) before start port checking (useful for long starting apps)

Cli

Run:

dev-gateway serve app.js -p 3000 -h localhost
  • -p, --port - port
  • -h, --host - host
  • -S, --skip - skip whole rule by slug
  • -s, --skip-run - skip running stage by slug (it can be useful if you want to run microservice manually, but you still needed requests proxying)

Extract:

dev-gateway extract app.js --dest example.com --output rules.json

Will extract current configuration to rules.json file

  • -d, --dest - destination
  • -o, --output - output file with rules

In action

Clone this repo and run:

npm install
npm run example

You can check test server in the test/example directory.

Alternatives

  • serve-micro-cluster - Easily start a local cluster of micro-based services using a simple rules.json file. It's like Path Alias on now, but for local development.
  • micro-cluster - Run multiple micro servers and a front proxy at a time, with a simple configuration file.

Author

Dmitry Pavlovsky