2021-10-21 22:42:27 +00:00
|
|
|
const asyncWrapper = require('../../middleware/asyncWrapper');
|
|
|
|
const App = require('../../models/App');
|
|
|
|
const { Sequelize } = require('sequelize');
|
|
|
|
const loadConfig = require('../../utils/loadConfig');
|
|
|
|
|
|
|
|
const { useKubernetes, useDocker } = require('./docker');
|
|
|
|
|
|
|
|
// @desc Get all apps
|
|
|
|
// @route GET /api/apps
|
|
|
|
// @access Public
|
|
|
|
const getAllApps = asyncWrapper(async (req, res, next) => {
|
|
|
|
const {
|
|
|
|
useOrdering: orderType,
|
|
|
|
dockerApps: useDockerAPI,
|
|
|
|
kubernetesApps: useKubernetesAPI,
|
|
|
|
} = await loadConfig();
|
|
|
|
|
|
|
|
let apps;
|
|
|
|
|
|
|
|
if (useDockerAPI) {
|
|
|
|
await useDocker(apps);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (useKubernetesAPI) {
|
|
|
|
await useKubernetes(apps);
|
|
|
|
}
|
|
|
|
|
2021-11-11 15:01:56 +00:00
|
|
|
// apps visibility
|
|
|
|
const where = req.isAuthenticated ? {} : { isPublic: true };
|
|
|
|
|
2021-11-22 15:45:59 +00:00
|
|
|
const order =
|
|
|
|
orderType == 'name'
|
|
|
|
? [[Sequelize.fn('lower', Sequelize.col('name')), 'ASC']]
|
|
|
|
: [[orderType, 'ASC']];
|
|
|
|
|
|
|
|
apps = await App.findAll({
|
|
|
|
order,
|
|
|
|
where,
|
|
|
|
});
|
2021-10-21 22:42:27 +00:00
|
|
|
|
|
|
|
if (process.env.NODE_ENV === 'production') {
|
|
|
|
// Set header to fetch containers info every time
|
|
|
|
return res.status(200).setHeader('Cache-Control', 'no-store').json({
|
|
|
|
success: true,
|
|
|
|
data: apps,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
res.status(200).json({
|
|
|
|
success: true,
|
|
|
|
data: apps,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = getAllApps;
|