@intelrug/nestjs-bunnycdn
v0.1.1
Published
Integrates BunnyCDN with Nest
Downloads
10
Readme
@intelrug/nestjs-bunnycdn
Integrates BunnyCDN with Nest
Install
$ yarn add @intelrug/nestjs-bunnycdn
Usage
BunnyCDNModule.forRoot(options, connection?)
import { Module } from '@nestjs/common';
import { BunnyCDNModule } from '@intelrug/nestjs-bunnycdn';
import { AppController } from './app.controller';
@Module({
imports: [
BunnyCDNModule.forRoot({
apiAccessKey: 'your-key',
storageZones: [{
name: 'your-storage-zone-name',
accessKey: 'your-storage-zone-access-key'
}],
}),
],
controllers: [AppController],
})
export class AppModule {}
BunnyCDNModule.forRootAsync(options, connection?)
import { Module } from '@nestjs/common';
import { BunnyCDNModule } from '@intelrug/nestjs-bunnycdn';
import { AppController } from './app.controller';
@Module({
imports: [
BunnyCDNModule.forRootAsync({
useFactory: () => ({
apiAccessKey: 'your-key',
storageZones: [{
name: 'your-storage-zone-name',
accessKey: 'your-storage-zone-access-key'
}],
}),
}),
],
controllers: [AppController],
})
export class AppModule {}
InjectBunnyCDN(connection?)
import { Controller, Get, } from '@nestjs/common';
import { InjectBunnyCDN } from '@intelrug/nestjs-bunnycdn';
import { BunnyCDN, PullZone } from '@intelrug/bunnycdn';
@Controller()
export class AppController {
constructor(
@InjectBunnyCDN() private readonly bunny: BunnyCDN,
) {}
@Get()
async getHello(): Promise<PullZone[]> {
try {
await this.bunny.pullZone.create({
Name: 'my-pull-zone',
OriginUrl: 'http://my-site.com',
Type: 0
});
return this.bunny.pullZone.get();
} catch (e) {
console.log(e);
}
}
}