@liberstudio/cloudflare-list
v2.2.7
Published
Modulo NestJS per gestione IP List Cloudflare
Readme
Modulo NestJS per la gestione IP List Cloudflare
Prima di iniziare
- Creare un account Cloudflare
- Scegliere il Dominio da utilizzare
- Manage Account > Configuration > List > Create List
- Account API tokens > Create Token > Create Custom Token (Permission: Account > Account WAF > Edit, Account > Account Filter List > Edit)
- Salvare il token API senza scadenza
- Domains > Scegliere il dominio da utilizzare
- Andare nella categoria Security > Security Rules > Create rule > Custom Rules
- Nome: , Field: <IP Source Address , is in, scegli la lista creata prima>, Action: Block
- Salvare la regola
Installazione
npm install @liberstudio/cloudflare-listUtilizzo
Configurazione
Nel file di configurazione del progetto, aggiungere il modulo all'import della configurazione:
import { CloudflareAttacksModule } from "@liberstudio/cloudflare-list";
@Module({
imports: [
CloudflareAttacksModule.forRoot({
accountId: "<account_id>",
listId: "<list_id>",
apiToken: "<api_token>",
comment: "<comment>",
logPath: "<logPath>",
excludedPaths: "<excludedList>",
silentPaths: "<silentList>",
}),
],
})
export class AppModule {}Versione Asincrona con ConfigModule
import { CloudflareAttacksModule } from "@liberstudio/cloudflare-list";
@Module({
imports: [
CloudflareAttacksModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: (config: ConfigService) => ({
apiToken: config.getOrThrow<string>("CLOUDFLARE_API_TOKEN"),
accountId: config.getOrThrow<string>("CLOUDFLARE_ACCOUNT_ID"),
listId: config.getOrThrow<string>("CLOUDFLARE_LIST_ID"),
comment: config.get<string>("CLOUDFLARE_LIST_COMMENT") || "Blocked",
logPath: config.get<string>("CLOUDFLARE_LIST_LOG_PATH") || "/var/log/nestjs-attacks.log",
excludedPaths: ["/api/health", "/api/webhook", /^\/api\/public\/.*/],
silentPaths: ["/auth/me", "/auth/refresh"],
}),
}),
],
})
export class AppModule {}License
This project is licensed under the MIT License - see the LICENSE file for details.
