https://github.com/selfagency/strapi-cdn-url-rewrite
Strapi controller module to rewrite upload URLs to CDN
https://github.com/selfagency/strapi-cdn-url-rewrite
cdn-support strapi strapi-plugin
Last synced: 7 months ago
JSON representation
Strapi controller module to rewrite upload URLs to CDN
- Host: GitHub
- URL: https://github.com/selfagency/strapi-cdn-url-rewrite
- Owner: selfagency
- Created: 2021-07-10T05:07:53.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2024-11-20T13:14:18.000Z (11 months ago)
- Last Synced: 2025-02-24T07:07:13.784Z (7 months ago)
- Topics: cdn-support, strapi, strapi-plugin
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/strapi-cdn-url-rewrite
- Size: 157 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Welcome to strapi-cdn-url-rewrite 👋
[](#)
[](https://twitter.com/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
```sh
yarn add strapi-cdn-url-rewrite
```## Use
Add your storage and CDN endpoints to your `.env` file like so:
```bash
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}`:
```javascript
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
```javascript
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](https://gitlab.com/selfagency/strapi-cdn-url-rewrite).
## Show your support
Give a ⭐️ if this project helped you!
---
_This README was generated with ❤️ by [readme-md-generator](https://github.com/kefranabg/readme-md-generator)_