Deploy with Docker Compose / deploy (push) Successful in 52s
A second "Cheapest night" tab on /hotels scans every candidate check-in between two dates (filtered by weekday, 1-7 nights, up to ~3 months), keeps the N cheapest hotels per night, and prices TfL transport once per unique hotel so the whole range fits in the streaming window. Backend - travelodge.py: extract _shortlist/_make_row/_price_hotels/_apply_transport from run_search; add a 30-minute per-(location, dates, rooms) Travelodge result cache, a deadline on page fetches, and run_scan (parallel date fetches with per-date failure isolation, one TfL lookup per hotel). - main.py: HotelRequestBase shared by search and scan requests, HotelScanRequest with weekday/range validation, scan event models, _guarded slot wrapper, POST /hotels/scan/stream (NDJSON). - nginx: the streaming location now matches /py/hotels/(search|scan). Frontend - Split CheapHotels.vue into SingleStayPanel, CheapestNightPanel, SharedFields, HotelRows, a shared form composable, stream/format helpers and hotels-shared.css; shared fields keep their values across tabs. - Vite dev server proxies /py to the Python API. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01H5P3C1HbbEwLZEYsjwr7uV
418 lines
15 KiB
Plaintext
418 lines
15 KiB
Plaintext
events {
|
|
worker_connections 1024;
|
|
}
|
|
|
|
http {
|
|
include /etc/nginx/mime.types;
|
|
default_type application/octet-stream;
|
|
|
|
server_tokens off;
|
|
charset utf-8;
|
|
|
|
resolver 127.0.0.11 valid=10s;
|
|
|
|
client_max_body_size 50M;
|
|
|
|
limit_req_zone $binary_remote_addr zone=login:10m rate=5r/m;
|
|
limit_req_zone $binary_remote_addr zone=api:10m rate=30r/s;
|
|
limit_req_zone $binary_remote_addr zone=upload:10m rate=5r/m;
|
|
limit_req_zone $binary_remote_addr zone=hotel_search:10m rate=3r/m;
|
|
|
|
log_format compact
|
|
'$remote_addr "$request" $status rt=$request_time';
|
|
|
|
access_log /var/log/nginx/access.log compact;
|
|
|
|
types {
|
|
text/javascript mjs;
|
|
}
|
|
|
|
gzip on;
|
|
gzip_vary on;
|
|
gzip_proxied any;
|
|
gzip_comp_level 6;
|
|
gzip_min_length 256;
|
|
gzip_types
|
|
text/plain
|
|
text/css
|
|
text/javascript
|
|
application/javascript
|
|
application/json
|
|
application/xml
|
|
image/svg+xml
|
|
font/woff2
|
|
application/font-woff2;
|
|
|
|
server {
|
|
listen 80;
|
|
server_name $DOMAIN www.$DOMAIN;
|
|
|
|
set $upstream_backend http://$BACKEND_HOST:$BACKEND_PORT;
|
|
set $upstream_icecast http://$ICECAST_HOST:$ICECAST_PORT;
|
|
set $upstream_gitea http://$GITEA_HOST:$GITEA_PORT;
|
|
set $upstream_hasura http://$HASURA_HOST:$HASURA_PORT;
|
|
set $upstream_quartz http://$QUARTZ_HOST:$QUARTZ_PORT;
|
|
set $upstream_python http://$PYTHON_HOST:$PYTHON_PORT;
|
|
|
|
location /uploads/ {
|
|
alias /uploads/;
|
|
add_header X-Content-Type-Options nosniff always;
|
|
add_header Content-Disposition "inline" always;
|
|
add_header Content-Security-Policy "default-src 'none'; img-src 'self'; style-src 'none'; script-src 'none'" always;
|
|
}
|
|
|
|
location / {
|
|
proxy_pass http://vue:5173;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection "upgrade";
|
|
proxy_set_header Host $host;
|
|
}
|
|
|
|
location $BACKEND_ENDPOINT {
|
|
return 301 $BACKEND_ENDPOINT/;
|
|
}
|
|
|
|
location $BACKEND_ENDPOINT/ws {
|
|
rewrite ^$BACKEND_ENDPOINT/(.*)$ /$1 break;
|
|
proxy_pass $upstream_backend;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection "upgrade";
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
}
|
|
|
|
location $BACKEND_ENDPOINT/auth/login {
|
|
limit_req zone=login burst=3 nodelay;
|
|
rewrite ^$BACKEND_ENDPOINT/(.*)$ /$1 break;
|
|
proxy_pass $upstream_backend;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
}
|
|
|
|
location $BACKEND_ENDPOINT/messages/upload {
|
|
limit_req zone=upload burst=3 nodelay;
|
|
rewrite ^$BACKEND_ENDPOINT/(.*)$ /$1 break;
|
|
proxy_pass $upstream_backend;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
}
|
|
|
|
location $BACKEND_ENDPOINT/ {
|
|
limit_req zone=api burst=20 nodelay;
|
|
rewrite ^$BACKEND_ENDPOINT/(.*)$ /$1 break;
|
|
proxy_pass $upstream_backend;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
}
|
|
|
|
location /radio {
|
|
return 301 /radio/;
|
|
}
|
|
|
|
location /radio/ {
|
|
rewrite ^/radio/(.*)$ /$1 break;
|
|
proxy_pass $upstream_icecast;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
}
|
|
|
|
location /gitea {
|
|
return 301 /gitea/;
|
|
}
|
|
|
|
location /gitea/ {
|
|
rewrite ^/gitea/(.*)$ /$1 break;
|
|
proxy_pass $upstream_gitea;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
}
|
|
|
|
location /hasura {
|
|
return 301 /hasura/;
|
|
}
|
|
|
|
location /hasura/ {
|
|
auth_request /internal/auth/admin-validate;
|
|
error_page 401 403 = @auth_denied;
|
|
rewrite ^/hasura/(.*)$ /$1 break;
|
|
proxy_pass $upstream_hasura;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection "upgrade";
|
|
}
|
|
|
|
location /notes {
|
|
return 301 /notes/;
|
|
}
|
|
|
|
location /notes/ {
|
|
auth_request /internal/auth/admin-validate;
|
|
error_page 401 403 = @auth_denied;
|
|
rewrite ^/notes/(.*)$ /$1 break;
|
|
proxy_pass $upstream_quartz;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection "upgrade";
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
}
|
|
|
|
location /py {
|
|
return 301 /py/;
|
|
}
|
|
|
|
# /py/hotels/search[/stream] and /py/hotels/scan/stream: long-running NDJSON streams
|
|
location ~ ^/py/hotels/(search|scan) {
|
|
# Public, up-to-a-minute upstream call with a single search slot: keep it to a few per minute per IP
|
|
limit_req zone=hotel_search burst=2 nodelay;
|
|
proxy_read_timeout 300s;
|
|
proxy_send_timeout 300s;
|
|
# The stream variant sends NDJSON progress lines; pass them through as they arrive
|
|
proxy_buffering off;
|
|
proxy_cache off;
|
|
gzip off;
|
|
rewrite ^/py/(.*)$ /$1 break;
|
|
proxy_pass $upstream_python;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
}
|
|
|
|
location /py/ {
|
|
limit_req zone=api burst=20 nodelay;
|
|
# Hotel search blocks for up to a few minutes while it calls Travelodge and TfL
|
|
proxy_read_timeout 300s;
|
|
proxy_send_timeout 300s;
|
|
rewrite ^/py/(.*)$ /$1 break;
|
|
proxy_pass $upstream_python;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
}
|
|
|
|
location = /internal/auth/admin-validate {
|
|
internal;
|
|
rewrite ^ /auth/validate-admin break;
|
|
proxy_pass $upstream_backend;
|
|
proxy_pass_request_body off;
|
|
proxy_set_header Content-Length "";
|
|
proxy_set_header Cookie $http_cookie;
|
|
}
|
|
|
|
location @auth_denied {
|
|
return 302 /admin/login?redirect=$request_uri;
|
|
}
|
|
|
|
}
|
|
|
|
server {
|
|
listen 443 ssl;
|
|
server_name $DOMAIN www.$DOMAIN;
|
|
|
|
ssl_certificate /etc/letsencrypt/live/localhost/fullchain.pem;
|
|
ssl_certificate_key /etc/letsencrypt/live/localhost/privkey.pem;
|
|
|
|
set $upstream_backend http://$BACKEND_HOST:$BACKEND_PORT;
|
|
set $upstream_icecast http://$ICECAST_HOST:$ICECAST_PORT;
|
|
set $upstream_gitea http://$GITEA_HOST:$GITEA_PORT;
|
|
set $upstream_hasura http://$HASURA_HOST:$HASURA_PORT;
|
|
set $upstream_quartz http://$QUARTZ_HOST:$QUARTZ_PORT;
|
|
set $upstream_python http://$PYTHON_HOST:$PYTHON_PORT;
|
|
|
|
location /uploads/ {
|
|
alias /uploads/;
|
|
add_header X-Content-Type-Options nosniff always;
|
|
add_header Content-Disposition "inline" always;
|
|
add_header Content-Security-Policy "default-src 'none'; img-src 'self'; style-src 'none'; script-src 'none'" always;
|
|
}
|
|
|
|
location / {
|
|
proxy_pass http://vue:5173;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection "upgrade";
|
|
proxy_set_header Host $host;
|
|
}
|
|
|
|
location $BACKEND_ENDPOINT {
|
|
return 301 $BACKEND_ENDPOINT/;
|
|
}
|
|
|
|
location $BACKEND_ENDPOINT/ws {
|
|
rewrite ^$BACKEND_ENDPOINT/(.*)$ /$1 break;
|
|
proxy_pass $upstream_backend;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection "upgrade";
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
}
|
|
|
|
location $BACKEND_ENDPOINT/auth/login {
|
|
limit_req zone=login burst=3 nodelay;
|
|
rewrite ^$BACKEND_ENDPOINT/(.*)$ /$1 break;
|
|
proxy_pass $upstream_backend;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
}
|
|
|
|
location $BACKEND_ENDPOINT/messages/upload {
|
|
limit_req zone=upload burst=3 nodelay;
|
|
rewrite ^$BACKEND_ENDPOINT/(.*)$ /$1 break;
|
|
proxy_pass $upstream_backend;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
}
|
|
|
|
location $BACKEND_ENDPOINT/ {
|
|
limit_req zone=api burst=20 nodelay;
|
|
rewrite ^$BACKEND_ENDPOINT/(.*)$ /$1 break;
|
|
proxy_pass $upstream_backend;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
}
|
|
|
|
location /radio {
|
|
return 301 /radio/;
|
|
}
|
|
|
|
location /radio/ {
|
|
rewrite ^/radio/(.*)$ /$1 break;
|
|
proxy_pass $upstream_icecast;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
}
|
|
|
|
location /gitea {
|
|
return 301 /gitea/;
|
|
}
|
|
|
|
location /gitea/ {
|
|
rewrite ^/gitea/(.*)$ /$1 break;
|
|
proxy_pass $upstream_gitea;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
}
|
|
|
|
location /hasura {
|
|
return 301 /hasura/;
|
|
}
|
|
|
|
location /hasura/ {
|
|
auth_request /internal/auth/admin-validate;
|
|
error_page 401 403 = @auth_denied;
|
|
rewrite ^/hasura/(.*)$ /$1 break;
|
|
proxy_pass $upstream_hasura;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection "upgrade";
|
|
}
|
|
|
|
location /notes {
|
|
return 301 /notes/;
|
|
}
|
|
|
|
location /notes/ {
|
|
auth_request /internal/auth/admin-validate;
|
|
error_page 401 403 = @auth_denied;
|
|
rewrite ^/notes/(.*)$ /$1 break;
|
|
proxy_pass $upstream_quartz;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection "upgrade";
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
}
|
|
|
|
location /py {
|
|
return 301 /py/;
|
|
}
|
|
|
|
# /py/hotels/search[/stream] and /py/hotels/scan/stream: long-running NDJSON streams
|
|
location ~ ^/py/hotels/(search|scan) {
|
|
# Public, up-to-a-minute upstream call with a single search slot: keep it to a few per minute per IP
|
|
limit_req zone=hotel_search burst=2 nodelay;
|
|
proxy_read_timeout 300s;
|
|
proxy_send_timeout 300s;
|
|
# The stream variant sends NDJSON progress lines; pass them through as they arrive
|
|
proxy_buffering off;
|
|
proxy_cache off;
|
|
gzip off;
|
|
rewrite ^/py/(.*)$ /$1 break;
|
|
proxy_pass $upstream_python;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
}
|
|
|
|
location /py/ {
|
|
limit_req zone=api burst=20 nodelay;
|
|
# Hotel search blocks for up to a few minutes while it calls Travelodge and TfL
|
|
proxy_read_timeout 300s;
|
|
proxy_send_timeout 300s;
|
|
rewrite ^/py/(.*)$ /$1 break;
|
|
proxy_pass $upstream_python;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
}
|
|
|
|
location = /internal/auth/admin-validate {
|
|
internal;
|
|
rewrite ^ /auth/validate-admin break;
|
|
proxy_pass $upstream_backend;
|
|
proxy_pass_request_body off;
|
|
proxy_set_header Content-Length "";
|
|
proxy_set_header Cookie $http_cookie;
|
|
}
|
|
|
|
location @auth_denied {
|
|
return 302 /admin/login?redirect=$request_uri;
|
|
}
|
|
|
|
}
|
|
|
|
}
|