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

serverless-server-spawner

v1.0.25

Published

[![NPM](https://img.shields.io/npm/v/serverless-server-spawner.svg?style=flat-square)](https://www.npmjs.com/package/serverless-server-spawner)

Downloads

87

Readme

Serverless Server Spawner

NPM

Demo

Basic idea:

  • Start it with npx serverless-server-spawner.
  • Invoke it with https://localhost:P/?cloneurl=C&branch=B
    • P - A configurable port.
    • C - A clone URL of a git Repo.
    • B - A branch in repo C.
  • It will
    • Clone that repo.
    • Checkout that branch.
    • Recognize what was cloned.
    • Find a free port
    • Spawn a server
    • Wait for the spawned server to start
    • Redirect to the spawned server
    • Keep that server alive for configurable amount of time

Repositories are recognized using configurable matchers. A matcher:

  • Determines a fitting name
  • How to prepare the repository before start
  • How to start the server

As the servers are spawned it will keep track of all processes. Provides an API as well as a dashboard showing status of the setup.

A simple flow

Use cases

  • Can be used to test feature-branches. Adding links from pull-requests to this server and let this server spawn servers running those features.
  • ...

See example in this sandbox: https://github.com/tomasbjerre/serverless-sandbox

Matchers

  • Put them in a folder
  • name them like *.matcher.js

Example: serverless-matchers/example.matcher.js

Content should be like:

function isMatching(repoFolder) {
  try {
    return require(`${repoFolder}/package.json`).scripts['start'] != undefined;
  } catch {
    return false;
  }
}

function getName(repoFolder) {
  return require(`${repoFolder}/package.json`).name;
}

function getPrepareCommand(repoFolder) {
  return `npm install`;
}

function preStart(repoFolder, env) {
  // Do struff before start
  // env contains port in evn.PORT
}

function getStartCommand(repoFolder) {
  // Environment variable named "PORT" contains the allocated port
  return `npm run start`;
}

function isReady(runLogContent, serverPort) {
  // Optionally check log to see if server ready.
  //return true;

  //return new RegExp(`https?://(127.0.0.1|localhost):${serverPort}`,'g')
  //  .test(runLogContent)

  return new RegExp(`${serverPort}`, 'g').test(runLogContent);
}

module.exports = {
  isMatching,
  getName,
  getPrepareCommand,
  preStart,
  getStartCommand,
  isReady,
};

And you point at them with:

npx serverless-server-spawner \
  --matchers-folder /path/to/serverless-matchers

Command line arguments

Usage: npx serverless-server-spawner [options]

Options:
  -V, --version                                        output the version number
  -ws, --workspace <folder>                            Filesystem to work with.
  -mf, --matchers-folder <folder>                      Folder containing matchers.
  -p, --port <number>                                  Server port to use (default: "8080")
  -d, --dashboard-url <url>                            Base URL of dashboard (default: "http://localhost:8080")
  -ttl, --time-to-live <minutes>                       Time to keep server running after it was started. (default: "30")
  -bbsat, --bitbucket-server-access-token <token>      Bitbucket Server access token
  -bbsu, --bitbucket-server-url <url>                  Bitbucket Server to use for REST integration (https://bbs/rest/api/latest)
  -bbsp, --bitbucket-server-projects <projects>        Bitbucket Server projects. Empty will include all projects.
  -mip, --minimum-port-number <port>                   Minimum port number to use for spawned servers (default: "9000")
  -map, --maximum-port-number <port>                   Maximum port number to use for spawned servers (default: "9999")
  -ict, --integration-cache-ttl <minutes>              Cache time to live, seconds (default: "120")
  -nc, --no-cleanup                                    Do not cleanup state on startup: kill servers and clean workspace
  -msbd, --minimum-seconds-between-dispatch <seconds>  Minimum time between spawning new servers from same url and branch (default: "10")
  -h, --help                                           display help for command

API

RESTful API of the this server.

The main entry point for new repo/branches is dispatch. It will start a server and, when started, redirect user to it.

GET /api/dispatch?cloneurl={cloneUrl}&branch={branch}
GET /api/servers
GET /api/servers/:id
GET /api/servers/:id/state

Stop, and cleanup, the server.

POST /api/servers/:id/stop
GET /api/servers/:id/log/spawn
GET /api/servers/:id/log/clone
GET /api/servers/:id/log/prepare
GET /api/servers/:id/log/run

If a Git service was configured, this will respond with clone URL:s in that service.

GET /api/cloneurlcategories

If a Git service was configured, this will respond with branches in categories.

GET /api/cloneurlcategories/:category1/:category2/branches

Clear all caches.

POST /api/clearcache

Get settings used, like port range. So that you can calculate available ports.

GET /api/settings

Developer instructions

During development it might help to start it with:

npm install \
 && npm run build \
 && node ./lib/spawner/bin.js \
 --matchers-folder /home/bjerre/workspace/serverless/serverless-sandbox/matchers \
 --time-to-live 1