changes for easier dev setup

This commit is contained in:
Evan
2026-01-17 01:49:03 +05:00
parent 7b66396050
commit 4ca4a3e199
2 changed files with 28 additions and 3 deletions

View File

@@ -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<TurnstileSettings> options)
public TurnstileService(HttpClient httpClient, IOptions<TurnstileSettings> 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<TurnstileResponse> ValidateTokenAsync(string token, string remoteip = null)
{
if (_env.IsDevelopment() && token == "DEV_BYPASS_TOKEN")
{
return new TurnstileResponse { Success = true };
}
var parameters = new Dictionary<string, string>
{
{ "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; }

View File

@@ -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: