more async'ification

This commit is contained in:
Girish Ramakrishnan
2021-09-07 09:57:49 -07:00
parent e7f51d992f
commit 7709e155e0
15 changed files with 267 additions and 400 deletions

View File

@@ -7,7 +7,6 @@ exports = module.exports = {
const apps = require('./apps.js'),
assert = require('assert'),
BoxError = require('./boxerror.js'),
constants = require('./constants.js'),
express = require('express'),
debug = require('debug')('box:dockerproxy'),
@@ -18,6 +17,7 @@ const apps = require('./apps.js'),
path = require('path'),
paths = require('./paths.js'),
safe = require('safetydance'),
util = require('util'),
_ = require('underscore');
let gHttpServer = null;
@@ -107,18 +107,17 @@ function process(req, res, next) {
}
}
function start(callback) {
assert.strictEqual(typeof callback, 'function');
async function start() {
assert(gHttpServer === null, 'Already started');
let json = middleware.json({ strict: true });
const json = middleware.json({ strict: true });
// we protect container create as the app/admin can otherwise mount random paths (like the ghost file)
// protected other paths is done by preventing install/exec access of apps using docker addon
let router = new express.Router();
const router = new express.Router();
router.post('/:version/containers/create', containersCreate);
let proxyServer = express();
const proxyServer = express();
if (constants.TEST) {
proxyServer.use(function (req, res, next) {
@@ -135,7 +134,6 @@ function start(callback) {
.use(middleware.lastMile());
gHttpServer = http.createServer(proxyServer);
gHttpServer.listen(constants.DOCKER_PROXY_PORT, '172.18.0.1', callback);
// Overwrite the default 2min request timeout. This is required for large builds for example
gHttpServer.setTimeout(60 * 60 * 1000);
@@ -169,14 +167,12 @@ function start(callback) {
client.pipe(remote).pipe(client);
});
});
await util.promisify(gHttpServer.listen.bind(gHttpServer))(constants.DOCKER_PROXY_PORT, '172.18.0.1');
}
function stop(callback) {
assert.strictEqual(typeof callback, 'function');
async function stop() {
if (gHttpServer) gHttpServer.close();
gHttpServer = null;
callback();
}