From 4ca4a3e19945ab651e9fa239a1fc58fb048c0aa8 Mon Sep 17 00:00:00 2001 From: Evan Date: Sat, 17 Jan 2026 01:49:03 +0500 Subject: [PATCH] changes for easier dev setup --- Submission.Api/Controllers/SignController.cs | 13 +++++++++++-- compose.yaml | 18 +++++++++++++++++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/Submission.Api/Controllers/SignController.cs b/Submission.Api/Controllers/SignController.cs index 51af945..8e81249 100644 --- a/Submission.Api/Controllers/SignController.cs +++ b/Submission.Api/Controllers/SignController.cs @@ -1,5 +1,7 @@ using Ashi.MongoInterface.Service; using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Hosting; using Microsoft.AspNetCore.RateLimiting; using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Options; @@ -164,16 +166,23 @@ namespace Submission.Api.Controllers { private readonly HttpClient _httpClient; private readonly string _secretKey; + private readonly IWebHostEnvironment _env; private const string SiteverifyUrl = "https://challenges.cloudflare.com/turnstile/v0/siteverify"; - public TurnstileService(HttpClient httpClient, IOptions options) + public TurnstileService(HttpClient httpClient, IOptions options, IWebHostEnvironment env) { _httpClient = httpClient; _secretKey = options?.Value?.SecretKey ?? throw new ArgumentNullException(nameof(options), "Turnstile:SecretKey must be configured in appsettings.json"); + _env = env; } public async Task ValidateTokenAsync(string token, string remoteip = null) { + if (_env.IsDevelopment() && token == "DEV_BYPASS_TOKEN") + { + return new TurnstileResponse { Success = true }; + } + var parameters = new Dictionary { { "secret", _secretKey }, @@ -214,7 +223,7 @@ namespace Submission.Api.Controllers [JsonPropertyName("success")] public bool Success { get; set; } - // Cloudflare returns "error-codes" (with a hyphen) — map it explicitly + // Cloudflare returns "error-codes" (with a hyphen) — map it explicitly [JsonPropertyName("error-codes")] public string[] ErrorCodes { get; set; } diff --git a/compose.yaml b/compose.yaml index e142b87..038e4aa 100644 --- a/compose.yaml +++ b/compose.yaml @@ -1,4 +1,13 @@ services: + mongodb: + image: mongo:7 + networks: + - app-network + ports: + - "27017:27017" + volumes: + - mongodb_data:/data/db + submission.api: image: submission.api build: @@ -8,9 +17,14 @@ - app-network expose: - "8080" + depends_on: + - mongodb environment: + - ASPNETCORE_ENVIRONMENT=Development - ASPNETCORE_URLS=http://+:8080 - - MongoDbSettings__ConnectionString=mongodb://host.docker.internal:27017 + - MongoDbSettings__ConnectionString=mongodb://mongodb:27017 + - MongoDbSettings__DatabaseName=petition_database + - PetitionSettings__AllowPetitionCreation=true nginx: image: petition-nginx @@ -28,3 +42,5 @@ networks: app-network: driver: bridge +volumes: + mongodb_data: