Telegraph icon indicating copy to clipboard operation
Telegraph copied to clipboard

How to proxy requests?

Open red010182 opened this issue 3 years ago • 0 comments
trafficstars

I'm using telegraph to serve a local html folder. However, I need to send a post request to a remote server which I can't add CORS header.

So I need to proxy the post request. I'm trying to do this

class ProxyHandler: HTTPRequestHandler {
    func respond(to request: HTTPRequest, nextHandler: HTTPRequest.Handler) throws -> HTTPResponse? {
        
        if request.method == .POST {
            request.uri = URI("http://my-domain.com")!
        }
        
        let response = try nextHandler(request)
        response?.headers.accessControlAllowOrigin = "*"

        return response
    }
}

But my client (WKWebview) got 404 response. Can anyone help?

Thanks

red010182 avatar May 21 '22 05:05 red010182