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');
|
2021-12-14 15:18:46 +00:00
|
|
|
const sentry = require('../../../shared/sentry');
|
|
|
|
const errorHandler = require('@tryghost/mw-error-handler');
|
2022-05-02 16:00:15 +01:00
|
|
|
const APIVersionCompatibilityService = require('../../services/api-version-compatibility');
|
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')());
|
|
|
|
}
|
|
|
|
|
2022-05-05 08:45:24 +01:00
|
|
|
apiApp.use(APIVersionCompatibilityService.versionRewrites);
|
2022-05-02 17:01:54 +01:00
|
|
|
apiApp.use(APIVersionCompatibilityService.contentVersion);
|
|
|
|
|
2022-04-06 13:36:12 +01:00
|
|
|
apiApp.lazyUse('/content/', require('./canary/content/app'));
|
|
|
|
apiApp.lazyUse('/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);
|
2022-05-02 16:00:15 +01:00
|
|
|
apiApp.use(APIVersionCompatibilityService.errorHandler);
|
2022-05-07 15:28:28 +01:00
|
|
|
apiApp.use(errorHandler.handleJSONResponse(sentry));
|
2020-04-27 16:54:31 +01:00
|
|
|
|
|
|
|
debug('Parent API setup end');
|
|
|
|
return apiApp;
|
|
|
|
};
|