Conditional reverse proxy

Sorry for the delay on this :see_no_evil: I sorta forgot about this thread and it fell off my radar since last week.

Okay I got it working I think. This config is the testcase basically.

:8881 {
	reverse_proxy :8882 {
		method GET
		header_up ngrok-skip-browser-warning true

		@no-tunnel {
			status 404
			header Ngrok-Error-Code ERR_NGROK_3200
		}
		handle_response @no-tunnel {
			reverse_proxy :8883
		}

		handle_response {
			reverse_proxy :8882 {
				header_up ngrok-skip-browser-warning true
			}
		}
	}
}

:8882 {
	handle /nope {
		header Ngrok-Error-Code ERR_NGROK_3200
		respond 404
	}
	respond "Hello 8882 (ngrok): {http.request.body}" 200
}

:8883 {
	respond "Hello 8883: {http.request.body}" 200
}

I think the key is not using forward_auth cause it has its own assumptions, but instead just using reverse_proxy with method GET and then it should work?

Requests to test:

$ curl -v http://localhost:8881 --data 'HERES A PAYLOAD'
Hello 8882 (ngrok): HERES A PAYLOAD

$ curl -v http://localhost:8881/nope --data 'HERES A PAYLOAD'
Hello 8883: HERES A PAYLOAD

So when you hit /nope it “acts like ngrok is dead” and instead serves from :8883.

That is what you want to do, correct?

2 Likes