Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ The API will be available at `http://localhost:3000`.

Push to `main` → GitHub Actions builds the Docker image, pushes to GHCR, then triggers Render to pull and deploy.

### Live Demo

- **API**: [taskforge-api-9i9h.onrender.com](https://taskforge-api-9i9h.onrender.com)
- **Swagger Docs**: [taskforge-api-9i9h.onrender.com/docs](https://taskforge-api-9i9h.onrender.com/docs)

> **Note:** Hosted on Render's free tier — the service sleeps after 15 minutes of inactivity. If the first request hangs, it's waking up (~30 seconds). Just wait and retry.

## API documentation

Swagger UI is available at `/docs` once the server is running.
Expand Down
2 changes: 2 additions & 0 deletions src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { Controller, Get } from "@nestjs/common";
import { AllowAnonymous } from "@thallesp/nestjs-better-auth";
import { SkipArcjet } from "./common/guards/arcjet-optional.guard.js";

@Controller()
export class AppController {
@Get()
@AllowAnonymous()
@SkipArcjet()
getRoot() {
return {
message: "Welcome to the Taskforge API",
Expand Down
35 changes: 35 additions & 0 deletions src/common/guards/arcjet-optional.guard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import type { ArcjetNest } from "@arcjet/nest";
import { ARCJET, ArcjetGuard } from "@arcjet/nest";
import {
type ExecutionContext,
Inject,
Injectable,
SetMetadata,
} from "@nestjs/common";
import { Reflector } from "@nestjs/core";

export const SKIP_ARCJET = "skip_arcjet";
export const SkipArcjet = () => SetMetadata(SKIP_ARCJET, true);

@Injectable()
export class ArcjetOptionalGuard extends ArcjetGuard {
constructor(
@Inject(ARCJET) aj: ArcjetNest,
private readonly reflector: Reflector,
) {
super(aj);
}

override async canActivate(context: ExecutionContext): Promise<boolean> {
const skipArcjet = this.reflector.getAllAndOverride<boolean>(SKIP_ARCJET, [
context.getHandler(),
context.getClass(),
]);

if (skipArcjet) {
return true;
}

return super.canActivate(context);
}
}
17 changes: 14 additions & 3 deletions src/lib/security/arcjet.module.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
import type { ArcjetNest } from "@arcjet/nest";
import {
ArcjetGuard,
ARCJET,
ArcjetModule,
cloudflare,
detectBot,
shield,
slidingWindow,
} from "@arcjet/nest";
import { Module } from "@nestjs/common";
import { ConfigService } from "@nestjs/config";
import { APP_GUARD } from "@nestjs/core";
import { APP_GUARD, Reflector } from "@nestjs/core";
import { ArcjetOptionalGuard } from "../../common/guards/arcjet-optional.guard.js";

@Module({
imports: [
ArcjetModule.forRootAsync({
isGlobal: true,
useFactory: (configService: ConfigService) => ({
key: configService.getOrThrow("ARCJET_KEY"),
proxies: [cloudflare()],
rules: [
detectBot({
mode: "LIVE",
Expand All @@ -31,6 +35,13 @@ import { APP_GUARD } from "@nestjs/core";
inject: [ConfigService],
}),
],
providers: [{ provide: APP_GUARD, useClass: ArcjetGuard }],
providers: [
{
provide: APP_GUARD,
useFactory: (aj: ArcjetNest, reflector: Reflector) =>
new ArcjetOptionalGuard(aj, reflector),
inject: [ARCJET, Reflector],
},
],
})
export class ArcjetSecurityModule {}
6 changes: 5 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { BadRequestException, ValidationPipe } from "@nestjs/common";
import { ConfigService } from "@nestjs/config";
import { NestFactory, Reflector } from "@nestjs/core";
import type { NestExpressApplication } from "@nestjs/platform-express";
import { DocumentBuilder, SwaggerModule } from "@nestjs/swagger";
import { AppModule } from "./app.module.js";
import { AllExceptionsFilter } from "./common/filters/all-exceptions.filter.js";
import { TransformInterceptor } from "./common/interceptors/transform.interceptor.js";

async function bootstrap() {
const app = await NestFactory.create(AppModule, { bodyParser: false });
const app = await NestFactory.create<NestExpressApplication>(AppModule, {
bodyParser: false,
});
app.set("trust proxy", true);

const configService = app.get(ConfigService);

Expand Down
Loading