Open valeeum opened 7 months ago
Nothing special just you can write the same shortly.
But it's not just there for convenience since it can cause error if not set:
// Redirect
if (res.statusCode==201 || (res.statusCode >= 300 && res.statusCode < 400 && res.statusCode !== 304)) {
const location = ctx.meta.$location;
/* istanbul ignore next */
if (!location) {
this.logger.warn(`The 'ctx.meta.$location' is missing for status code '${res.statusCode}'!`);
} else {
res.setHeader("Location", location);
}
}
I suggest we use the following code:
const location = ctx.meta.$location ?? ctx.meta.$responseHeaders?.['Location'];
Good catch
I'm just curious why ctx.meta.$location & ctx.meta.$responseType options are offered as opposed to setting "Location" and "Content-Type" header via ctx.meta.$responseHeaders?