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

@porscheofficial/vercel-static-extensions

v1.0.2

Published

A plug-and-play solution to implement authentication through Entra ID for static sites hosted on Vercel.

Downloads

231

Readme

@porscheofficial/vercel-static-extensions

A plug-and-play solution to implement authentication through Entra ID for static sites hosted on Vercel. This is only relevant for specific use cases, where the static assets are generated during the build and not known in advance. This package implements the Vercel Build Output API to explicitly define which assets to deploy on which infrastructure, otherwise Vercel might not recognize API Routes as such and deploys them as static assets.

How to use it

  1. Install the package:
npm install @porscheofficial/vercel-static-extensions
  1. Add the following script to your package.json:

PNPM has issues with postbuild, in that case, just exec the script as part of your build script.

{
  "scripts": {
    "postbuild": "vercel-static-extensions"
  }
}
  1. Optionally create your configuration file: vercel-static-extensions.config.json
{
  "staticDirectory": "build",
  "extensions": {
    "authentication": {
      "provider": "microsoft-entra-id",
      "environmentVariables": {
        "AUTH_MICROSOFT_ENTRA_CLIENT_ID": "AUTH_MICROSOFT_ENTRA_CLIENT_ID1",
        "AUTH_MICROSOFT_ENTRA_ID_SECRET": "AUTH_MICROSOFT_ENTRA_ID_SECRET2",
        "AUTH_MICROSOFT_ENTRA_ID_TENANT_ID": "AUTH_MICROSOFT_ENTRA_ID_TENANT_ID2",
        "AUTH_MICROSOFT_ENTRA_ID_REDIRECT_URI": "AUTH_MICROSOFT_ENTRA_ID_REDIRECT_URI2"
      }
    }
  }
}
  1. Create or update the vercel.json file:
{
  "routes": [
    {
      "src": "/api/auth/(.*)",
      "dest": "/api/auth/[...nextauth]/route.js"
    }
  ]
}

What does the script do?

The script does the following:

  • Move the static files into .vercel/output/static
  • Create .vercel/output/functions with the Authentication API routes and Middlelayer functions
  • Create .vercel/output/config.json with the routes configuration

Limitations

This script is intended to add an authentication layer to static sites hosted on Vercel. It's highly opinionated and might not work for all use cases.

Why is this script necessary?

We faced challenges deploying static assets with API routes created during build time, such as with the Technology Radar, to Vercel. This script explicitly defines which assets to deploy on which infrastructure.

First try

During the build process, we created a directory /build and moved the functions to /build/api. Unfortunately, Vercel treated all files in that build directory as static files and didn't execute the functions.

Second try

We created a vercel.json and referenced the API Directory. This resulted in an error, because the API Directory is not part of the repository but is only created during build time. The vercel.json File seems to be interpreted before the build.

Third try

We created the API directory in the root of the repository (/api) and let Vercel transpile the typescript files. Unfortunately, this resulted in an error because next-auth uses __dirname which is not available in the Edge Environment (Middleware). Running esbuild manually allows to replace the __dirname variable.

Fourth try – Working Alternative

Following the first approach, we created the API directory within the build directory (/build/api), but with the difference that we did that via Github Actions and only then pushed the artifacts to Vercel. That means, after the build, we cd into the build directory (/build) and then run the CLI vercel deploy. That works because then all the assets are already there, and Vercel correctly interprets the API files as functions. The downside of this approach is that we do not leverage Vercel Build Infrastructure.

Solution

We decided implement the Vercel Output API to tell Vercel exactly how to run our artifacts. By doing that, it is possible to create the assets during build time on Vercel's Infrastructure and then deploy them correctly.

License

See LICENSE.md for more information.