move wellKnownJson to domains

after some more thought:
* If app moves to another location, user has to remember to move all this config
* It's not really associated with an app. It's to do with the domain info
* We can put some hints in the UI if app is missing.

part of #703
This commit is contained in:
Girish Ramakrishnan
2020-12-23 15:34:23 -08:00
parent 8a17e13ec4
commit 663e0952fc
24 changed files with 100 additions and 98 deletions
-17
View File
@@ -32,7 +32,6 @@ exports = module.exports = {
setLocation,
setDataDir,
setMounts,
setWellKnown,
stop,
start,
@@ -797,19 +796,3 @@ function setMounts(req, res, next) {
next(new HttpSuccess(202, { taskId: result.taskId }));
});
}
function setWellKnown(req, res, next) {
assert.strictEqual(typeof req.body, 'object');
assert.strictEqual(typeof req.resource, 'object');
if (typeof req.body.wellKnown !== 'object') return next(new HttpError(400, 'wellKnown must be an object'));
if (req.body.wellKnown) {
if (Object.keys(req.body.wellKnown).some(k => typeof req.body.wellKnown[k] !== 'string')) return next(new HttpError(400, 'wellKnown is a map of strings'));
}
apps.setWellKnown(req.resource, req.body.wellKnown, auditSource.fromRequest(req), function (error, result) {
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(200, {}));
});
}
+9 -1
View File
@@ -99,6 +99,13 @@ function update(req, res, next) {
if (!req.body.tlsConfig.provider || typeof req.body.tlsConfig.provider !== 'string') return next(new HttpError(400, 'tlsConfig.provider must be a string'));
}
if ('wellKnown' in req.body) {
if (typeof req.body.wellKnown !== 'object') return next(new HttpError(400, 'wellKnown must be an object'));
if (req.body.wellKnown) {
if (Object.keys(req.body.wellKnown).some(k => typeof req.body.wellKnown[k] !== 'string')) return next(new HttpError(400, 'wellKnown is a map of strings'));
}
}
// some DNS providers like DigitalOcean take a really long time to verify credentials (https://github.com/expressjs/timeout/issues/26)
req.clearTimeout();
@@ -107,7 +114,8 @@ function update(req, res, next) {
provider: req.body.provider,
config: req.body.config,
fallbackCertificate: req.body.fallbackCertificate || null,
tlsConfig: req.body.tlsConfig || { provider: 'letsencrypt-prod' }
tlsConfig: req.body.tlsConfig || { provider: 'letsencrypt-prod' },
wellKnown: req.body.wellKnown || null
};
domains.update(req.params.domain, data, auditSource.fromRequest(req), function (error) {
+4 -4
View File
@@ -4,18 +4,18 @@ exports = module.exports = {
get
};
const apps = require('../apps.js'),
const domains = require('../domains.js'),
HttpError = require('connect-lastmile').HttpError;
function get(req, res, next) {
const host = req.headers['host'];
apps.getByFqdn(host, function (error, app) {
domains.get(host, function (error, domain) {
if (error) return next(new HttpError(404, error.message));
const location = req.params[0];
if (!app.wellKnown || !(location in app.wellKnown)) return next(new HttpError(404, 'No custom well-known config'));
if (!domain.wellKnown || !(location in domain.wellKnown)) return next(new HttpError(404, 'No custom well-known config'));
res.status(200).send(app.wellKnown[location]);
res.status(200).send(domain.wellKnown[location]);
});
}