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

caravaggio-plugin-nextjs

v0.4.2

Published

Plugin to easily integrate caravaggio with nextjs

Downloads

56

Readme

Caravaggio - NextJS

This plugin let you use caravaggio with NextJS in an easy way. It transforms any image relative url to an absolute url for the current NextJS instance.

Any caravaggio url like this

https://mynextjs.com/api/assets/rs,s:300x?image=/logo.png

gets transformed into

https://mynextjs.com/api/assets/rs,s:300x?image=https://mynextjs.com/logo.png

For a complete description of how to use this plugin, read the article "NextJS + Caravaggio, serve images like a rockstar!".

Usage

Add this plugin to your Caravaggio instance

// api/assets/[...params].js

import caravaggio from 'caravaggio';
import nextPlugin from 'caravaggio-plugin-nextjs';

const ONE_MONTH = 60 * 60 * 24 * 30;

export default caravaggio({
  basePath: '/api/assets',
  browserCache: `s-maxage=${ONE_MONTH}`,
  plugins: {
    plugins: [{
      name: 'nextjs',
      instance: nextPlugin()
    }]
  }
});

Options

Various options can be passed to the plugin constructor

  • baseUrl: optional. This plugin will do its best to understand where your NextJS app is hosted. If you want to force this value pass baseUrl. It must be a complete url like https://my-next.com
  • protocol: optional. You can pass http or https to force the protocol. If baseUrl is passed , this value is ignored. By default the plugin will check NODE_ENV value and it uses https if it's production.

How this works

This plugin will try to understand where your NextJS website is hosted. If you pass baseUrl options, it will be used, otherwise it checks for VERCEL_URL value. If you setup this environment variable the plugin will use it. Otherwise it will check the host header in the current request. To understand if it must use http or https, it will check protocol if you pass it, otherwise it check the value of NODE_ENV and uses https if the variable is production.