Telegraph
Telegraph copied to clipboard
How to proxy requests?
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