mailserver: a056bcfd broke mail server restart
after proxying, we never restarted the mail server also add note that restart has to reconfigure
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
exports = module.exports = {
|
||||
proxy,
|
||||
restart,
|
||||
proxyAndRestart,
|
||||
queueProxy,
|
||||
|
||||
setLocation,
|
||||
@@ -21,12 +21,6 @@ const assert = require('assert'),
|
||||
services = require('../services.js'),
|
||||
url = require('url');
|
||||
|
||||
// because of how the proxy middleware works, the http response is already sent by the time this function is called
|
||||
async function restart(req, res, next) {
|
||||
await safe(mailServer.restart(), { debug });
|
||||
next();
|
||||
}
|
||||
|
||||
async function proxyToMailContainer(port, pathname, req, res, next) {
|
||||
const parsedUrl = url.parse(req.url, true /* parseQueryString */);
|
||||
|
||||
@@ -46,7 +40,7 @@ async function proxyToMailContainer(port, pathname, req, res, next) {
|
||||
|
||||
req.clearTimeout(); // TODO: add timeout to mail server proxy logic instead of this
|
||||
mailserverProxy(req, res, function (error) {
|
||||
if (!error) return; // response was already sent by proxy, do not proceed to connect-lastmile
|
||||
if (!error) return next(); // note: response was already sent by proxy by this point
|
||||
|
||||
if (error.code === 'ECONNREFUSED') return next(new HttpError(424, 'Unable to connect to mail server'));
|
||||
if (error.code === 'ECONNRESET') return next(new HttpError(424, 'Unable to query mail server'));
|
||||
@@ -58,7 +52,22 @@ async function proxyToMailContainer(port, pathname, req, res, next) {
|
||||
async function proxy(req, res, next) {
|
||||
const pathname = req.path.split('/').pop();
|
||||
|
||||
proxyToMailContainer(3000, pathname, req, res, next);
|
||||
proxyToMailContainer(3000, pathname, req, res, function (httpError) {
|
||||
if (httpError) return next(httpError);
|
||||
|
||||
// for success, the proxy already sent the response. do not proceed to connect-lastmile which will result in double headers
|
||||
});
|
||||
}
|
||||
|
||||
async function proxyAndRestart(req, res, next) {
|
||||
const pathname = req.path.split('/').pop();
|
||||
|
||||
proxyToMailContainer(3000, pathname, req, res, async function (httpError) {
|
||||
if (httpError) return next(httpError);
|
||||
|
||||
// for success, the proxy already sent the response. do not proceed to connect-lastmile which will result in double headers
|
||||
await safe(mailServer.restart(), { debug });
|
||||
});
|
||||
}
|
||||
|
||||
async function queueProxy(req, res, next) {
|
||||
|
||||
Reference in New Issue
Block a user