forked from Shared/esg
Add health check and retry logic and circuit breaker
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
# Testing providers through an authorized server
|
||||
|
||||
The gateway already supports an outbound SOCKS5 proxy through `OUTBOUND_PROXY`.
|
||||
You can create that proxy locally with standard OpenSSH dynamic forwarding; no
|
||||
Termius installation or application code changes are required on the server.
|
||||
|
||||
## 1. Confirm SSH access
|
||||
|
||||
Use an SSH key through your SSH agent when possible. A password can also be
|
||||
entered interactively by `ssh`, but do not put it in `.env`, a shell command, or
|
||||
the repository.
|
||||
|
||||
```bash
|
||||
ssh your-user@authorized-server.example
|
||||
```
|
||||
|
||||
The authorized server must be allowed to reach the provider URLs configured in
|
||||
your environment. The server does not need a SOCKS daemon; the SSH daemon
|
||||
provides the dynamic forwarding endpoint.
|
||||
|
||||
## 2. Open the local SOCKS tunnel
|
||||
|
||||
From the project root, run this in a dedicated terminal:
|
||||
|
||||
```bash
|
||||
SSH_TUNNEL_HOST=authorized-server.example \
|
||||
SSH_TUNNEL_USER=your-user \
|
||||
SOCKS_PORT=4030 \
|
||||
npm run tunnel:provider
|
||||
```
|
||||
|
||||
Optional variables:
|
||||
|
||||
- `SSH_TUNNEL_PORT` — SSH port, default `22`.
|
||||
- `SSH_IDENTITY_FILE` — private key path when it is not already loaded in the SSH agent.
|
||||
- `SOCKS_BIND_HOST` — keep the default `127.0.0.1`; do not bind the proxy publicly.
|
||||
|
||||
The command is equivalent to:
|
||||
|
||||
```bash
|
||||
ssh -N -D 127.0.0.1:4030 your-user@authorized-server.example
|
||||
```
|
||||
|
||||
Keep the tunnel terminal open. `socks5h` is important because it makes DNS
|
||||
resolution happen through the authorized server rather than on the restricted
|
||||
local network.
|
||||
|
||||
## 3. Configure the local gateway
|
||||
|
||||
In the local `.env` used by the gateway:
|
||||
|
||||
```ini
|
||||
OUTBOUND_PROXY=socks5h://127.0.0.1:4030
|
||||
OUTBOUND_HTTP_DEBUG=false
|
||||
```
|
||||
|
||||
The application’s Axios clients will route provider calls through the tunnel.
|
||||
The gateway itself, MongoDB, and the client used to call the gateway remain
|
||||
local.
|
||||
|
||||
Start the application in a second terminal:
|
||||
|
||||
```bash
|
||||
npm run start:dev
|
||||
```
|
||||
|
||||
Before running a real inquiry, verify that the tunnel can resolve and reach a
|
||||
provider host. For example, if `curl` is available:
|
||||
|
||||
```bash
|
||||
curl --proxy socks5h://127.0.0.1:4030 \
|
||||
--connect-timeout 10 \
|
||||
https://provider-host.example/health
|
||||
```
|
||||
|
||||
Use a real provider URL that is safe to probe; some legacy SOAP endpoints do
|
||||
not expose a health route, in which case a DNS/TCP check is sufficient.
|
||||
|
||||
## 4. Run a smoke inquiry
|
||||
|
||||
The smoke suite calls the local gateway. Only the gateway’s outbound provider
|
||||
requests use the SOCKS tunnel:
|
||||
|
||||
```bash
|
||||
ESG_SMOKE_ENABLED=true \
|
||||
SMOKE_GATEWAY_BASE_URL=http://127.0.0.1:8085 \
|
||||
SMOKE_INQUIRY_PATH=/inquiry/person \
|
||||
SMOKE_ACCESS_TOKEN='your-local-access-token' \
|
||||
SMOKE_INQUIRY_PAYLOAD='{"nationalCode":"0012345678","birthDate":"1370-05-15"}' \
|
||||
npm run smoke
|
||||
```
|
||||
|
||||
If your local gateway uses another port or route prefix, change the smoke
|
||||
variables to match it.
|
||||
|
||||
## Alternative: run the gateway on the authorized server
|
||||
|
||||
If policy allows deployment there, running the gateway itself on the authorized
|
||||
server removes the SOCKS hop. You can still access its HTTP port locally with
|
||||
an ordinary SSH local forward:
|
||||
|
||||
```bash
|
||||
ssh -N -L 8085:127.0.0.1:8085 your-user@authorized-server.example
|
||||
```
|
||||
|
||||
This alternative requires MongoDB and the application environment to be set up
|
||||
on the server. The SOCKS approach is usually simpler for local development.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
- `channel open failed`: SSH forwarding may be disabled by server policy; ask the server administrator to allow TCP forwarding.
|
||||
- Provider DNS fails locally but works with `curl --proxy socks5h://...`: ensure `OUTBOUND_PROXY` uses `socks5h`, not `socks5`.
|
||||
- The app ignores the tunnel: restart it after changing `.env`; outbound clients read the proxy setting during process startup.
|
||||
- Port already in use: choose another `SOCKS_PORT` and update `OUTBOUND_PROXY` to the same port.
|
||||
Reference in New Issue
Block a user