GithubHelp home page GithubHelp logo

selfagency / strapi-cdn-url-rewrite Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 0.0 53 KB

Strapi controller module to rewrite upload URLs to CDN

Home Page: https://www.npmjs.com/package/strapi-cdn-url-rewrite

JavaScript 100.00%
strapi strapi-plugin cdn-support

strapi-cdn-url-rewrite's Introduction

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

strapi-cdn-url-rewrite's People

Contributors

selfagency avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.