Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: simple reverse proxy for web browser #13

Open
coolaj86 opened this issue Jul 10, 2024 · 0 comments
Open

doc: simple reverse proxy for web browser #13

coolaj86 opened this issue Jul 10, 2024 · 0 comments

Comments

@coolaj86
Copy link
Member

coolaj86 commented Jul 10, 2024

In order to get this working in the browser I needed a port forward proxy (from the testnet server to my desktop), and a CORS-enabled server (to allow the web browser to use the other port to access the testnet server).

# ssh -NT -L <local-port>:<target-host>:<target-port> <remote-host>
ssh -NT -L 19998:127.0.0.1:19998 my-dashd-testnet-server

# or to background it:
# ssh -nNT -L 19998:127.0.0.1:19998 my-dashd-testnet-server

/etc/hosts:

127.0.0.1   local.example.com

Caddyfile:

http://local.example.com {
    #tls internal

    log {
        output stdout
        format console
    }

    handle /* {
        root * ./
        file_server {
            browse
        }
    }
}

# CORS Preflight (OPTIONS) + Request (GET, POST, PATCH, PUT, DELETE)
(cors-api) {
    @match-cors-api-preflight {
        #not header Origin "{http.request.scheme}://{http.request.host}"
        header Origin "{http.request.header.origin}"
        method OPTIONS
    }
    handle @match-cors-api-preflight {
        header {
            Access-Control-Allow-Origin "{http.request.header.origin}"
            Access-Control-Allow-Methods "GET, POST, PUT, PATCH, DELETE, OPTIONS"
            Access-Control-Allow-Headers "Origin, Accept, Authorization, Content-Type, X-Requested-With"
            Access-Control-Allow-Credentials "true"
            Access-Control-Max-Age "3600"
            defer
        }
        respond "" 204
    }

    @match-cors-api-request {
        #not header Origin "{http.request.scheme}://{http.request.host}"
        header Origin "{http.request.header.origin}"
        not method OPTIONS
    }
    handle @match-cors-api-request {
        header {
            Access-Control-Allow-Origin "{http.request.header.origin}"
            Access-Control-Allow-Credentials "true"
            Access-Control-Max-Age "3600"
            defer
        }
    }
}

http://local.example.com:19999 {

    log {
        output stdout
        format console
    }

    handle /* {
        import cors-api
        reverse_proxy localhost:19998
    }
}
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

No branches or pull requests

1 participant