automate wellknown setup
the main reason this is under app and not domain is because it let's the user know that an app has to be installed for the whole thing to work. part of #703
This commit is contained in:
@@ -32,6 +32,7 @@ exports = module.exports = {
|
||||
setLocation,
|
||||
setDataDir,
|
||||
setMounts,
|
||||
setWellKnown,
|
||||
|
||||
stop,
|
||||
start,
|
||||
@@ -44,6 +45,7 @@ exports = module.exports = {
|
||||
uploadFile,
|
||||
downloadFile,
|
||||
|
||||
|
||||
load
|
||||
};
|
||||
|
||||
@@ -795,3 +797,19 @@ 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, {}));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -25,5 +25,6 @@ exports = module.exports = {
|
||||
tasks: require('./tasks.js'),
|
||||
tokens: require('./tokens.js'),
|
||||
users: require('./users.js'),
|
||||
volumes: require('./volumes.js')
|
||||
volumes: require('./volumes.js'),
|
||||
wellknown: require('./wellknown.js')
|
||||
};
|
||||
|
||||
21
src/routes/wellknown.js
Normal file
21
src/routes/wellknown.js
Normal file
@@ -0,0 +1,21 @@
|
||||
'use strict';
|
||||
|
||||
exports = module.exports = {
|
||||
get
|
||||
};
|
||||
|
||||
const apps = require('../apps.js'),
|
||||
HttpError = require('connect-lastmile').HttpError;
|
||||
|
||||
function get(req, res, next) {
|
||||
const host = req.headers['host'];
|
||||
|
||||
apps.getByFqdn(host, function (error, app) {
|
||||
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'));
|
||||
|
||||
res.status(200).send(app.wellKnown[location]);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user