diff --git a/src/apps.js b/src/apps.js index e3eb863e9..d3567984b 100644 --- a/src/apps.js +++ b/src/apps.js @@ -424,7 +424,7 @@ function install(appId, appStoreId, manifest, location, portBindings, accessRest }); } -function configure(appId, location, portBindings, accessRestriction, cert, key, memoryLimit, callback) { +function configure(appId, location, portBindings, accessRestriction, cert, key, memoryLimit, altDomain, callback) { assert.strictEqual(typeof appId, 'string'); assert.strictEqual(typeof location, 'string'); assert.strictEqual(typeof portBindings, 'object'); @@ -432,6 +432,7 @@ function configure(appId, location, portBindings, accessRestriction, cert, key, assert(cert === null || typeof cert === 'string'); assert(key === null || typeof key === 'string'); assert.strictEqual(typeof memoryLimit, 'number'); + assert(altDomain === null || typeof altDomain === 'string'); assert.strictEqual(typeof callback, 'function'); var error = validateHostname(location, config.fqdn()); @@ -443,6 +444,8 @@ function configure(appId, location, portBindings, accessRestriction, cert, key, error = certificates.validateCertificate(cert, key, config.appFqdn(location)); if (error) return callback(new AppsError(AppsError.BAD_CERTIFICATE, error.message)); + if (altDomain !== null && !validator.isFQDN(altDomain)) return callback(new AppsError(AppsError.BAD_FIELD, 'Invalid alt domain')); + appdb.get(appId, function (error, app) { if (error && error.reason === DatabaseError.NOT_FOUND) return callback(new AppsError(AppsError.NOT_FOUND, 'No such app')); if (error) return callback(new AppsError(AppsError.INTERNAL_ERROR, error)); @@ -467,6 +470,7 @@ function configure(appId, location, portBindings, accessRestriction, cert, key, accessRestriction: accessRestriction, portBindings: portBindings, memoryLimit: memoryLimit, + altDomain: altDomain, oldConfig: { location: app.location, diff --git a/src/routes/apps.js b/src/routes/apps.js index 587096fd8..b7ae34f6d 100644 --- a/src/routes/apps.js +++ b/src/routes/apps.js @@ -168,10 +168,11 @@ function configureApp(req, res, next) { if (data.cert && !data.key) return next(new HttpError(400, 'key must be provided')); if (!data.cert && data.key) return next(new HttpError(400, 'cert must be provided')); if ('memoryLimit' in data && typeof data.memoryLimit !== 'number') return next(new HttpError(400, 'memoryLimit is not a number')); + if (data.altDomain && typeof data.altDomain !== 'string') return next(new HttpError(400, 'altDomain must be a string')); debug('Configuring app id:%s location:%s bindings:%j accessRestriction:%j memoryLimit:%s', req.params.id, data.location, data.portBindings, data.accessRestriction, data.memoryLimit); - apps.configure(req.params.id, data.location, data.portBindings || null, data.accessRestriction, data.cert || null, data.key || null, data.memoryLimit || 0, function (error) { + apps.configure(req.params.id, data.location, data.portBindings || null, data.accessRestriction, data.cert || null, data.key || null, data.memoryLimit || 0, data.altDomain || null, function (error) { if (error && error.reason === AppsError.ALREADY_EXISTS) return next(new HttpError(409, error.message)); if (error && error.reason === AppsError.PORT_RESERVED) return next(new HttpError(409, 'Port ' + error.message + ' is reserved.')); if (error && error.reason === AppsError.PORT_CONFLICT) return next(new HttpError(409, 'Port ' + error.message + ' is already in use.'));