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

@sanalytics/probot-serverless-now

v1.0.7

Published

An extension for running Probot on now.sh v2

Downloads

26

Readme

now.sh extension for Probot

A Probot extension to make it easier to run your Probot Apps serverless on now.sh v2.

This extension is based on @probot/serverless-lambda and uses much of its code.

Usage

$ npm install @sanalytics/probot-serverless-now
// index.js
import { serverless } from '@sanalytics/probot-serverless-now';
import app from './app';

// the following is different from serverless-lambda, as the current working directory does not contain the package.json on now.sh v2
import { name as appName, version as appVersion } from '../package.json';

// make sure to pass appName and appVersion
export default serverless(app, appName, appVersion);
// app.js
import { Application } from 'probot';

export default (app: Application) => {
  app.on('issues.opened', async context => {
    // A new issue was opened, what should we do with it?
    context.log(context.payload);
  });
};

Configuration

This package moves the functionality of probot run into a handler suitable for usage on now.sh v2. Follow the documentation on Environment Configuration to setup your app's environment variables. You can add these to .env, but for security reasons you may want to use the now CLI to set Environment Variables for the function so you don't have to include any secrets in the deployed package.

Since you might run into issues with limits related to now.sh environment variables and secrets, just use the pem keyfile (or create one using the key included in your .env file where all \n are replaced with actual new lines) together with now-cli:

now secret add private_key "$(cat key.pem | base64)"

Then set the environment variable PRIVATE_KEY either in your now.json as shown below or in your deploy command with now -e PRIVATE_KEY="@private_key@

{
  "env": {
    "PRIVATE_KEY": "@private_key"
  }
}

To decode the private key during your app startup, use node's Buffer.from before you initalize your app:

process.env.PRIVATE_KEY = Buffer.from(process.env.PRIVATE_KEY, 'base64').toString('binary');

Differences from probot run

Local Development

Since now.sh functions do not start a normal node process, the best way we've found to test this out locally is to use zeit/micro. Having a dev script in your package.json allows you to continue working from https://localhost:3000/probot before deploying your function to now.sh. When you're developing with typescript, make sure to run npm i -D typescript ts-node micro-dev @types/node @types/micro and npm i micro probot

{
  "scripts": {
    "dev": "ts-node --typeCheck node_modules/.bin/micro-dev src/index.ts"
  }
}

Long running tasks

Some Probot Apps that depend on long running processes or intervals might not work with this extension or result in high costs. This is due to the inherent architecture of serverless functions, which are designed to respond to events and stop running as quickly as possible. For longer running apps we recommend using other deployment options.

Only responds to Webhooks from GitHub

This extension is designed primarily for receiving webhooks from GitHub and responding back as a GitHub App. If you are using HTTP Routes in your app to serve additional pages, you should take a look at serverless-http, which can be used with Probot's express server by wrapping probot.server.