Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions backend/internal/proxy-host.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,56 @@ const internalProxyHost = {
});
},

/**
* @param {Access} access
* @param {Object} data
* @param {String} data.domain
* @param {Array} [data.expand]
* @param {Array} [data.omit]
* @return {Promise}
*/
getByDomain: (access, data) => {
if (typeof data === 'undefined') {
data = {};
}

return access.can('proxy_hosts:get', data.domain)
.then((access_data) => {
let query = proxyHostModel
.query()
.where('is_deleted', 0)
.andWhere(castJsonIfNeed('domain_names'), 'like', '%' + data.domain + '%')
.allowGraph('[owner,access_list.[clients,items],certificate]')
.modify(function(queryBuilder) {
if (data.expand) {
queryBuilder.withGraphFetched(`[${data.expand.join(', ')}]`);
}
})
.first();

if (access_data.permission_visibility !== 'all') {
query.andWhere('owner_user_id', access.token.getUserId(1));
}

if (typeof data.expand !== 'undefined' && data.expand !== null) {
query.withGraphFetched('[' + data.expand.join(', ') + ']');
}

return query.then(utils.omitRow(omissions()));
})
.then((row) => {
if (!row || !row.id) {
throw new error.ItemNotFoundError(data.id);
}
row = internalHost.cleanRowCertificateMeta(row);
// Custom omissions
if (typeof data.omit !== 'undefined' && data.omit !== null) {
row = _.omit(row, data.omit);
}
return row;
});
},

/**
* @param {Access} access
* @param {Object} data
Expand Down
46 changes: 46 additions & 0 deletions backend/routes/nginx/proxy_hosts.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,52 @@ router
.catch(next);
});

/**
* Specific proxy-host by domain
*
* /api/nginx/proxy-hosts/domain/:domain
*/
router
.route('/domain/:domain')
.options((req, res) => {
res.sendStatus(204);
})
.all(jwtdecode())

/**
* GET /api/nginx/proxy-hosts/domain/:domain
*
* Retrieve a specific proxy-host by domain
*/
.get((req, res, next) => {
validator({
required: ['domain'],
additionalProperties: false,
properties: {
domain: {
type: 'string'
},
expand: {
$ref: 'common#/properties/expand'
}
}
}, {
domain: req.params.domain,
expand: (typeof req.query.expand === 'string' ? req.query.expand.split(',') : null)
})
.then((data) => {
return internalProxyHost.getByDomain(res.locals.access, {
domain: data.domain,
expand: data.expand
});
})
.then((row) => {
res.status(200)
.send(row);
})
.catch(next);
});

/**
* Enable proxy-host
*
Expand Down