Skip to content

Instantly share code, notes, and snippets.

@bathizte
Last active January 30, 2024 09:26
Show Gist options
  • Save bathizte/80f40f27f02452f98fd6 to your computer and use it in GitHub Desktop.
Save bathizte/80f40f27f02452f98fd6 to your computer and use it in GitHub Desktop.
Lighttpd CORS reverse proxy for transmission
# Lighttpd as a CORS reverse proxy to Transmission XML-RPC API
server.modules = (
"mod_rewrite",
"mod_setenv",
"mod_proxy"
)
server.document-root = "/var/www"
# CORS preflighted request (HTTP OPTIONS) not handled yet by Transmission : Emulate a 200 OK
$HTTP["request-method"] =~ "^OPTIONS$" {
url.rewrite = ( "^.*$" => "/index.html")
}
# Proxy other requests to Transmission (YMMV)
$HTTP["request-method"] =~ "^(GET|POST)$" {
proxy.server = (
"/bt/rpc" => (
"transmission-rpc" => (
"host" => "127.0.0.1",
"port" => 9091
)
)
)
}
# CORS Headers
setenv.add-response-header = (
"Access-Control-Allow-Origin" => "*",
"Access-Control-Allow-Headers" => "accept, origin, x-requested-with, content-type, x-transmission-session-id",
"Access-Control-Expose-Headers" => "X-Transmission-Session-Id",
"Access-Control-Allow-Methods" => "GET, POST, OPTIONS"
)
@stokito
Copy link

stokito commented Jan 18, 2023

The cors headers are needed only if the method is OPTIONS so you can try:

$HTTP["request-method"] =~ "^(OPTIONS)$" {
  setenv.add-response-header = ( 
          "Access-Control-Allow-Origin" => "*", 
          "Access-Control-Allow-Headers" => "accept, origin, x-requested-with, content-type, x-transmission-session-id",
          "Access-Control-Expose-Headers" => "X-Transmission-Session-Id",
          "Access-Control-Allow-Methods" => "GET, POST, OPTIONS"
  )
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment