New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

caravaggio-plugin-nextjs

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

caravaggio-plugin-nextjs

Plugin to easily integrate caravaggio with nextjs

  • 0.4.2
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
9
increased by28.57%
Maintainers
1
Weekly downloads
 
Created
Source

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.

FAQs

Package last updated on 29 Oct 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc