2021-06-15 17:01:22 +01:00
|
|
|
const debug = require('@tryghost/debug')('web:api:default:app');
|
2020-08-10 16:19:09 +01:00
|
|
|
const config = require('../../../shared/config');
|
2020-04-25 20:53:58 +01:00
|
|
|
const express = require('../../../shared/express');
|
2020-05-28 05:57:02 -05:00
|
|
|
const urlUtils = require('../../../shared/url-utils');
|
2021-12-14 15:18:46 +00:00
|
|
|
const sentry = require('../../../shared/sentry');
|
|
|
|
const errorHandler = require('@tryghost/mw-error-handler');
|
2020-04-27 16:54:31 +01:00
|
|
|
|
|
|
|
module.exports = function setupApiApp() {
|
|
|
|
debug('Parent API setup start');
|
2020-05-01 19:29:42 +01:00
|
|
|
const apiApp = express('api');
|
2020-04-27 16:54:31 +01:00
|
|
|
|
2020-08-10 16:19:09 +01:00
|
|
|
if (config.get('server:testmode')) {
|
|
|
|
apiApp.use(require('./testmode')());
|
|
|
|
}
|
|
|
|
|
2021-10-11 12:06:03 +02:00
|
|
|
apiApp.lazyUse(urlUtils.getVersionPath({version: 'v2', type: 'content'}), require('./v2/content/app'));
|
|
|
|
apiApp.lazyUse(urlUtils.getVersionPath({version: 'v2', type: 'admin'}), require('./v2/admin/app'));
|
2020-04-27 16:54:31 +01:00
|
|
|
|
2021-10-11 12:06:03 +02:00
|
|
|
apiApp.lazyUse(urlUtils.getVersionPath({version: 'v3', type: 'content'}), require('./v3/content/app'));
|
|
|
|
apiApp.lazyUse(urlUtils.getVersionPath({version: 'v3', type: 'admin'}), require('./v3/admin/app'));
|
2020-04-27 16:54:31 +01:00
|
|
|
|
2021-10-11 12:06:03 +02:00
|
|
|
apiApp.lazyUse(urlUtils.getVersionPath({version: 'v4', type: 'content'}), require('./canary/content/app'));
|
|
|
|
apiApp.lazyUse(urlUtils.getVersionPath({version: 'v4', type: 'admin'}), require('./canary/admin/app'));
|
2021-03-03 18:44:00 +13:00
|
|
|
|
2021-10-11 12:06:03 +02:00
|
|
|
apiApp.lazyUse(urlUtils.getVersionPath({version: 'canary', type: 'content'}), require('./canary/content/app'));
|
|
|
|
apiApp.lazyUse(urlUtils.getVersionPath({version: 'canary', type: 'admin'}), require('./canary/admin/app'));
|
2020-04-27 16:54:31 +01:00
|
|
|
|
|
|
|
// Error handling for requests to non-existent API versions
|
|
|
|
apiApp.use(errorHandler.resourceNotFound);
|
2021-12-14 15:18:46 +00:00
|
|
|
apiApp.use(errorHandler.handleJSONResponse(sentry));
|
2020-04-27 16:54:31 +01:00
|
|
|
|
|
|
|
debug('Parent API setup end');
|
|
|
|
return apiApp;
|
|
|
|
};
|