Skip to content

Support Reverse Proxy and SSL Protocol Detection#59

Open
alcayaga wants to merge 1 commit into
yomidevs:masterfrom
alcayaga:feat-reverse-proxy
Open

Support Reverse Proxy and SSL Protocol Detection#59
alcayaga wants to merge 1 commit into
yomidevs:masterfrom
alcayaga:feat-reverse-proxy

Conversation

@alcayaga
Copy link
Copy Markdown

Fixes #46

Summary

Adds support for running the local audio server behind a reverse proxy, specifically addressing issues with hardcoded binding and static URL generation in responses.

Changes

  • Configurable Binding: Added host and port settings to default_config.json. This allows users to change the binding from
    127.0.0.1 to 0.0.0.0 for external access while keeping the secure default for most users.
  • Dynamic Host & Protocol Detection:
    • The server now uses the Host header from incoming requests to build audio URLs.
    • It now detects the X-Forwarded-Proto header (commonly sent by proxies like Nginx) to determine if http or https should be used in the response.
  • Configuration Refactor: Centralized configuration management in plugin/config.py by removing hardcoded constants from plugin/consts.py and using a shared CONFIG object across the project.

Motivation

Previously, the server was hardcoded to bind to 127.0.0.1, and all audio URLs returned to Yomitan were hardcoded to http://127.0.0.1:5050. This made it impossible to use the server over a network or behind a proxy with SSL, as the client would receive unreachable local links.

How to Test

  1. Local default: Run the server normally. It should still bind to 127.0.0.1:5050 and return http links.
  2. Reverse Proxy simulation:
    • Set "host": "0.0.0.0" in config.json.
    • Send a request with proxy headers:
      curl -H "Host: my-proxy.net" -H "X-Forwarded-Proto: https" "http://localhost:5050/?term=読む"
    • Verify that the url fields in the JSON response start with https://my-proxy.net/.

- Add configurable 'host' and 'port' to default_config.json
- Dynamically detect Host and X-Forwarded-Proto headers for URL construction
- Refactor configuration management to use a central CONFIG object
- Remove hardcoded 127.0.0.1 binding to allow external access when configured
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Binding to 127.0.0.1

1 participant