Skip to content
This repository was archived by the owner on Nov 7, 2025. It is now read-only.
Draft
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
25 changes: 16 additions & 9 deletions packages/cms/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ function fetchAllSites(req, res, startSites) {
console.log('Fetch all sites')

if (!process.env.SITE_API_KEY) {
console.log('Site api key is not set!');
if (res) res.status(500).json({error: 'Site api key is not set!'});
return;
throw new Error('Site api key is not set!')
}

return fetch(`${apiUrl}/api/site`, {
Expand All @@ -111,10 +109,7 @@ function fetchAllSites(req, res, startSites) {
sitesById = newSitesById;

cleanUpSites();
}).catch((e) => {
console.error('An error occurred fetching the site config:', e);
if (res) res.status(500).json({error: 'An error occured fetching the sites data: ' + e});
});
})
}

// run through all sites see if anyone is not active anymore and needs to be shut down
Expand Down Expand Up @@ -268,12 +263,19 @@ module.exports.getMultiSiteApp = (options) => {
app.use(async function (req, res, next) {
if (Object.keys(sites).length === 0) {
console.log('Fetching config for all sites');
await fetchAllSites(req, res);
try {
await fetchAllSites(req, res);
} catch (e) {
console.error('An error occurred fetching the site config:', e);
if (res) return res.status(500).json({error: 'An error occured fetching the sites data: ' + e});
}
}

if (Object.keys(sites).length === 0) {
console.log('No config for sites found');
res.status(500).json({error: 'No sites found'});

return;
}

// add custom openstad configuration to ApostrhopheCMS
Expand All @@ -292,7 +294,12 @@ module.exports.getMultiSiteApp = (options) => {
const resetConfigMw = async (req, res, next) => {
let host = req.headers['x-forwarded-host'] || req.get('host');
host = host.replace(['http://', 'https://'], ['']);
await fetchAllSites(req, res);
try {
await fetchAllSites(req, res);
} catch (e) {
console.error('An error occurred fetching the site config:', e);
if (res) return res.status(500).json({error: 'An error occured fetching the sites data: ' + e});
}
req.forceRestart = true;
next();
Comment on lines +297 to 304

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to do an early return because we can only return one response to each request. Is the req.forceRestart doing something important?

The next() loads the next middleware, that middleware can emit another response.

}
Expand Down
2 changes: 2 additions & 0 deletions packages/cms/lib/modules/vimeo-upload/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ module.exports = {
res.status(500).json({
error: 'Vimeoconfig not existing'
});

return;
}

const _clientSecret = vimeoConfig.secret;
Expand Down