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

@alan-eu/now-whitelisted-static-build

v0.0.3

Published

This Builder allows you to build and deploy a static site to [now](https://zeit.co/docs/) while only giving access to whitelisted ips. It is based off of [`@now/static-build`](https://zeit.co/docs/v2/deployments/official-builders/static-build-now-static-b

Downloads

56

Readme

alan-now-whitelisted-static-build

This Builder allows you to build and deploy a static site to now while only giving access to whitelisted ips. It is based off of @now/static-build. The usage is exactly the same except there is an additional config option allowedIps which is an array of IP addresses that can access your site.

Usage

{
  "version": 2,
  "builds": [
    {
      "src": "package.json",
      "use": "@alan-eu/now-whitelisted-static-build",
      "config": { "allowedIps": ["some-ip-address"] }
    }
  ]
}

Deployment

In order for this builder to run on the now platform, the source code needs to be publicly available (see related issue). For this reason, this package is published to npm. The package home page is here.

Currently the deployment is done manually.

# make sure you are on acceptance and that the version
# in package.json has been bumped since the previous publish
cd alan-now-whitelisted-static-build
npm login # if you are not a part of the @alan-eu org in npm ping @terrence.wong or @cg
npm publish --access public

How Do Builders Work?

In the future, I may write a lengthier blog post about how Builders work. Here is a short overview:

The now platform has a serverless execution model. A deployed project will be made of many endpoints. These endpoints are also called lambdas. A lambda is simply a function that responds to an HTTP request.

A Builder is a module that transforms source files into lambdas. Zeit has created some utilities to help write your own custom builder. The utility that allows you to declare a lamba is called createLambda.

const { createLambda, FileBlob } = require('@now/build-utils')
exports.build = async () => {
  const lambda = await createLambda({
    runtime: 'nodejs8.10',
    handler: 'index.main',
    files: {
      'index.js': new FileBlob({ data: 'exports.main = () => {}' })
    }
  });
  return {
    output: {
      "/": lambda
    }
  }
}

The lambda above contains a single file called index.js and when the lambda executes, it should run the export main inside index.js.

To declare the endpoint for a lambda, the Builder module has an export called build which should return an object mapping paths to lambdas. In this case if someone requests the path "/", then our lambda will run.

Additional documentaiton on buidlers can be found here.

How Does This Builder Work?

This builder creates a single lambda at the endpoint ${srcBase}/serve-static-files-to-whitelisted-ips. srcBase is based off of your now.json file.

Example The endpoint the builder creates for the following now.json will be /design-system/serve-static-files-to-whitelisted-ips

{
  "version": 2,
  "builds": [
    {
      "src": "design-system/package.json",
      "use": "@alan-eu/now-whitelisted-static-build",
      "config": { "allowedIps": ["some-ip-address"] }
    }
  ]
}

This builder also sets up routing so that any request to /design-system/(.*) will execute the lambda as /design-system/serve-static-files-to-whitelisted-ips?pathname=$1.

When the lambda executes, it first checks that the requester's IP address is one of the allowedIps declared in now.json. If no, the builder returns 403. If yes, then the builder serves the file that was requested. If the path requested is a directory, then we try to serve an index.html file located in the directory.