🚀 DAY 5 OF LAUNCH WEEK:Introducing Webhook Events for Alert Changes.Learn more →
Socket
Book a DemoInstallSign in
Socket

strapi-cdn-url-rewrite

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

strapi-cdn-url-rewrite

Strapi controller module to rewrite upload URLs to CDN

latest
Source
npmnpm
Version
0.1.1
Version published
Maintainers
1
Created
Source

Welcome to strapi-cdn-url-rewrite 👋

License: MIT Twitter: self_agency

Strapi controller module to rewrite upload URLs to CDN. Swaps out your bucket URLs for your CDN URLs in your response data.

Install

yarn add strapi-cdn-url-rewrite

Use

Add your storage and CDN endpoints to your .env file like so:

STORAGE_ENDPOINT=https://your-bucket.storage.com
CDN_ENDPOINT=https://your-bucket.cdn.com

(You can also pass them directly if you don't want to use environmental variables. See below.)

Open your collection or single type's controller file (eg., ./api/{COLLECTION}/controllers/${COLLECTION}.js), and add the following, substituting your collection or single type's name in the place of {COLLECTION}:

const StrapiCdnUrlRewrite = require('strapi-cdn-url-rewrite')

const { cdnRewrite } = new StrapiCdnUrlRewrite()

module.exports = {
  async find(ctx) {
    return cdnRewrite(await strapi.services.{COLLECTION}.find(ctx.query))
  },
  async findOne(ctx) {
    const { id } = ctx.params
    return cdnRewrite(await strapi.services.{COLLECTION}.findOne({ id }))
  }
}

Full Parameters

const { cdnRewrite } = StrapiCdnUrlRewrite(storageUrl, cdnUrl)

storageUrl

Valid URL string to your storage bucket. Eg., https://your-bucket.s3.wasabisys.com.

cdnUrl

Valid URL string for your CDN endpoint Eg., https://your-bucket.b-cdn.com.

🤝 Contributing

Contributions, issues and feature requests are welcome!

Feel free to check issues page.

Show your support

Give a ⭐️ if this project helped you!

This README was generated with ❤️ by readme-md-generator

FAQs

Package last updated on 18 Mar 2021

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