Skip to content

502 Bad Gateway

The server acting as a middleman (proxy) received an invalid response from the upstream server it was trying to reach.

Use this proxying requests. If your Nginx server tries to talk to your Node.js app, but the Node app returns an invalid HTTP response, Nginx will return a 502 to the user.

import { HttpException, get } from 'shokupan';
export const proxyWeather = get('/weather', async () => {
const response = await fetch('http://upstream-weather-api.internal');
if (!response.ok) {
throw new HttpException('Upstream returned invalid response', 502);
}
return response.json();
});