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

@ceteio/cloudinary-memory-server

v1.2.0

Published

An in-memory mock server compatible with Cloudinary SDK methods for uploading and retrieving files.

Downloads

4

Readme

cloudinary-memory-server

An in-memory mock server compatible with Cloudinary SDK methods for uploading and retrieving files.

NOTE: No transformations are performed; the raw file is always returned.

Usage

Start the server

From the cli:

npx @ceteio/cloudinary-memory-server

or, in JS:

yarn add @ceteio/cloudinary-memory-server
const cloudinaryMemServer = require("@ceteio/cloudinary-memory-server");
cloudinaryMemServer();

Connect to the server

const cloudinary = require("cloudinary");

cloudinary.config({
  cloud_name: "na",
  api_key: "na",
  api_secret: "na",
  upload_prefix: "https://localhost:9443"
});

(NOTE: See SSL certificates below for important information to avoid SSL errors)

Supported endpoints

| Method | Path | | ------ | ----------------------------------------------- | | GET | /:cloudname/image/upload/:public_id | | POST | /:api_version/:cloudname/image/upload | | DELETE | /:api_version/:cloudname/resources/image/upload |

SSL certificates

The cloudinary node module (and possibly other languages also) require the upload_prefix to be a secure URL (ie; https). By default, cloudinary-memory-server will generate an SSL certificate to enable the secure URL.

However, this certificate will be regenerated each time cloudinary-memory-server is run, requiring manual approval in your browswer before images will load.

To skip the approval step, it's possible to create and install a permanent trusted certificate which can then be passed into cloudinary-memory-server.

Installing a trusted SSL certificate for localhost

The recommended tool is mkcert:

  1. Install mkcert
  2. Setup the RootCA:
    mkcert -install
  3. Create the certificates:
    cd <your-project-dir>
    mkcert -key-file localhost-key.pem -cert-file localhost.pem localhost 127.0.0.1 ::1
  4. Add .pem files to .gitignore:
    echo '*.pem' >> .gitignore
  5. Pass the certificate files to cloudinary-memory-server:
    SSL_KEY_FILE=localhost-key.pem SSL_CERT_FILE=localhost.pem npx @ceteio/cloudinary-memory-server
    or, in JavaScript:
    const cloudinaryMemServer = require("@ceteio/cloudinary-memory-server");
    cloudinaryMemServer({
      sslKeyFile: "./localhost-key.pem",
      sslCertFile: "./localhost.pem"
    });

Calling https URL from Node

When using the node cloudinary client, it is important to tell node that the SSL certificate used by cloudinary-memory-server can be trusted. How you do that depends on how you're setting up your SSL certificates.

With mkcert installed certificate

Node does not use the system root store, so it won't accept mkcert certificates automatically. Instead, you will have to set the NODE_EXTRA_CA_CERTS environment variable.

Given your node script is setup like so:

// index.js
const cloudinary = require("cloudinary");

cloudinary.config({
  cloud_name: "na",
  api_key: "na",
  api_secret: "na",
  upload_prefix: "https://localhost:9443"
});

Run it with the environment variable set:

NODE_EXTRA_CA_CERTS="$(mkcert -CAROOT)/rootCA.pem" node index.js

With default, temporary certificate (insecure)

Set the NODE_TLS_REJECT_UNAUTHORIZED env var, which tells node to trust all SSL certificates. This will trust the automatically generated certificate, but will also trust any https connection even if it would normally throw an error. This can pose a risk of Man In The Middle (MITM) attacks, and should be considered insecure.

Given your node script is setup like so:

// index.js
const cloudinary = require("cloudinary");

cloudinary.config({
  cloud_name: "na",
  api_key: "na",
  api_secret: "na",
  upload_prefix: "https://localhost:9443"
});

Run it insecurely with the environment variable set:

NODE_TLS_REJECT_UNAUTHORIZED=0 node index.js

Thanks