diff --git a/README.md b/README.md index a66f0fd..09d4d51 100644 --- a/README.md +++ b/README.md @@ -310,44 +310,80 @@ server { # SSE endpoints location ~ ^/api/v2/(spots|alerts)/stream { + proxy_pass http://127.0.0.1:8080; + + # Allow keep-alive proxy_http_version 1.1; proxy_set_header Connection ""; - proxy_pass http://127.0.0.1:8080; + + # Set correct content type for SSE API calls + add_header Content-Type text/event-stream always; + + # Set remove buffering, remove caching, add suitable timeouts for SSE API calls proxy_buffering off; proxy_cache off; proxy_read_timeout 24h; proxy_connect_timeout 10s; proxy_send_timeout 24h; proxy_set_header X-Accel-Buffering no; + add_header Cache-Control no-store always; + + # Allow cross-origin requests to API proxy_hide_header Access-Control-Allow-Origin; add_header Access-Control-Allow-Origin * always; - add_header Cache-Control no-store always; - add_header Content-Type text/event-stream always; + + # Pass on IP address and host information to Spothole, in case logging this information is required + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $http_host; + proxy_set_header X-Forwarded-Proto $scheme; } # Other API endpoints location /api/ { + proxy_pass http://127.0.0.1:8080; + + # Allow keep-alive proxy_http_version 1.1; proxy_set_header Connection ""; - proxy_pass http://127.0.0.1:8080; + + # Set up buffering, remove caching, add suitable timeouts for API calls proxy_buffering on; proxy_cache off; proxy_read_timeout 30s; proxy_connect_timeout 10s; + add_header Cache-Control no-store always; + + # Allow cross-origin requests to API proxy_hide_header Access-Control-Allow-Origin; add_header Access-Control-Allow-Origin * always; - add_header Cache-Control no-store always; + + # Pass on IP address and host information to Spothole, in case logging this information is required + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $http_host; + proxy_set_header X-Forwarded-Proto $scheme; } # Static assets location / { + proxy_pass http://127.0.0.1:8080; + + # Allow keep-alive proxy_http_version 1.1; proxy_set_header Connection ""; - proxy_pass http://127.0.0.1:8080; + + # Set up buffering and caching, add suitable timeouts for static asset requests proxy_buffering on; proxy_read_timeout 30s; proxy_connect_timeout 10s; add_header Cache-Control "public, max-age=3600, must-revalidate" always; + + # Pass on IP address and host information to Spothole, in case logging this information is required + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $http_host; + proxy_set_header X-Forwarded-Proto $scheme; } } ``` diff --git a/server/webserver.py b/server/webserver.py index 2e17f17..eb64bc3 100644 --- a/server/webserver.py +++ b/server/webserver.py @@ -119,8 +119,9 @@ class WebServer: app = tornado.web.Application(api_routes + v1_compat_routes + ui_routes + misc_routes, template_path=os.path.join(_HERE, "../templates"), + log_function=request_log, debug=False) - app.listen(self._port) + app.listen(self._port, xheaders=True) logging.info("Web server running on port " + str(WEB_SERVER_PORT)) await self._shutdown_event.wait() @@ -173,3 +174,22 @@ class WebServer: # Probably got deleted already on another thread pass pass + +def request_log(handler): + """Custom log function to provide more data about requests.""" + + if handler.get_status() < 500: + log_method = logging.info + else: + log_method = logging.warning + + request = handler.request + client_ip = request.remote_ip + referrer = request.headers.get("Referer", "-") + user_agent = request.headers.get("User-Agent", "-") + + log_method( + f'{client_ip} - "{request.method} {request.uri}" ' + f'{handler.get_status()} {request.request_time():.2f}ms | ' + f'Ref: {referrer} | UA: {user_agent}' + ) diff --git a/templates/about.html b/templates/about.html index f32b775..db9a44f 100644 --- a/templates/about.html +++ b/templates/about.html @@ -13,7 +13,7 @@ href="/apidocs">API documentation. The API delivers spots in a consistent format regardless of the data source, freeing developers from needing to know how each individual data source presents its data.
Spothole itself is also open source, Public Domain licenced code that anyone can take and modify. The source code is here.
+ href="https://git.ianrenton.com/ian/spothole/">The source code is here.The software was written by Ian Renton, MØTRT and other contributors. Full details are available in the README file.
diff --git a/templates/add_spot.html b/templates/add_spot.html index 9d2f007..da12fc5 100644 --- a/templates/add_spot.html +++ b/templates/add_spot.html @@ -76,7 +76,7 @@ - + diff --git a/templates/alerts.html b/templates/alerts.html index 8a57d49..f34e327 100644 --- a/templates/alerts.html +++ b/templates/alerts.html @@ -75,7 +75,7 @@ - + diff --git a/templates/bands.html b/templates/bands.html index bda6c4a..7694ad9 100644 --- a/templates/bands.html +++ b/templates/bands.html @@ -77,8 +77,8 @@ - - + + diff --git a/templates/base.html b/templates/base.html index 670eebe..f456c08 100644 --- a/templates/base.html +++ b/templates/base.html @@ -1,6 +1,6 @@ {% extends "skeleton.html" %} {% block head_extra %} - + @@ -10,10 +10,10 @@ - - - - + + + + {% end %} {% block body %}