From 01b560085ea4a2f97a109f1fe886e81cef8a874c Mon Sep 17 00:00:00 2001 From: Untone Date: Wed, 2 Oct 2024 18:29:08 +0300 Subject: [PATCH] test-nginx --- nginx.conf.sigil | 23 ++++++++++++++--------- src/main.rs | 3 +-- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/nginx.conf.sigil b/nginx.conf.sigil index 4c17396..6be8712 100644 --- a/nginx.conf.sigil +++ b/nginx.conf.sigil @@ -7,11 +7,6 @@ {{ $cors_headers_post := "if ($request_method = 'POST') { add_header 'Access-Control-Allow-Origin' '$allow_origin' always; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always; add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization' always; add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always; add_header 'Access-Control-Allow-Credentials' 'true' always; }" }} {{ $cors_headers_get := "if ($request_method = 'GET') { add_header 'Access-Control-Allow-Origin' '$allow_origin' always; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always; add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization' always; add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always; add_header 'Access-Control-Allow-Credentials' 'true' always; }" }} -# Mapping for allowed origins -map $http_origin $allow_origin { - ~^https?:\/\/((.*\.)?localhost(:\d+)?|discoursio-webapp(-(.*))?\.vercel\.app|(.*\.)?discours\.io)$ $http_origin; - default ""; -} # Server block setup {{ range $port_map := .PROXY_PORT_MAP | split " " }} @@ -43,8 +38,19 @@ server { keepalive_timeout 70; {{ end }} + location = / { + if ($request_method = GET) { + return 200 'ok'; + add_header Content-Type text/plain; + } + proxy_pass http://{{ $.APP }}-{{ $upstream_port }}; + {{ $proxy_settings }} + {{ $cors_headers_options }} + {{ $cors_headers_post }} + {{ $cors_headers_get }} + } + # Default location block - location / { proxy_pass http://{{ $.APP }}-{{ $upstream_port }}; add_header 'Cache-Control' 'no-cache'; @@ -61,9 +67,8 @@ server { {{ $cors_headers_get }} } - # Error pages - - error_page 400 401 402 403 405 406 407 408 409 410 411 412 413 414 415 416 417 418 420 422 423 424 426 428 429 431 444 449 450 451 /400-error.html; + # Error pages + error_page 400 401 402 403 405 406 407 408 409 410 411 412 413 414 415 416 417 418 420 422 423 424 426 428 429 431 444 449 450 451 /400-error.html; location /400-error.html { root /var/lib/dokku/data/nginx-vhosts/dokku-errors; internal; diff --git a/src/main.rs b/src/main.rs index 67a8ec1..ab36dec 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,9 +28,8 @@ async fn main() -> std::io::Result<()> { App::new() .app_data(web::Data::new(app_state.clone())) .wrap(Logger::default()) - .route("/", web::get().to(|| async { HttpResponse::Ok().body("ok") })) - .route("/{path:.*}", web::get().to(proxy_handler)) .route("/", web::post().to(upload_handler)) + .route("/{path:.*}", web::get().to(proxy_handler)) }) .bind("127.0.0.1:8080")? .run()