2020-04-27 18:54:31 +03:00
|
|
|
const debug = require('ghost-ignition').debug('web:api:default:app');
|
2020-08-10 18:19:09 +03:00
|
|
|
const config = require('../../../shared/config');
|
2020-04-25 22:53:58 +03:00
|
|
|
const express = require('../../../shared/express');
|
2020-05-28 13:57:02 +03:00
|
|
|
const urlUtils = require('../../../shared/url-utils');
|
2020-04-27 18:54:31 +03:00
|
|
|
const errorHandler = require('../shared/middlewares/error-handler');
|
|
|
|
|
|
|
|
module.exports = function setupApiApp() {
|
|
|
|
debug('Parent API setup start');
|
2020-05-01 21:29:42 +03:00
|
|
|
const apiApp = express('api');
|
2020-04-27 18:54:31 +03:00
|
|
|
|
2020-08-10 18:19:09 +03:00
|
|
|
if (config.get('server:testmode')) {
|
|
|
|
apiApp.use(require('./testmode')());
|
|
|
|
}
|
|
|
|
|
2020-04-27 18:54:31 +03:00
|
|
|
// Mount different API versions
|
|
|
|
apiApp.use(urlUtils.getVersionPath({version: 'v2', type: 'content'}), require('./v2/content/app')());
|
|
|
|
apiApp.use(urlUtils.getVersionPath({version: 'v2', type: 'admin'}), require('./v2/admin/app')());
|
|
|
|
|
|
|
|
apiApp.use(urlUtils.getVersionPath({version: 'v3', type: 'content'}), require('./canary/content/app')());
|
|
|
|
apiApp.use(urlUtils.getVersionPath({version: 'v3', type: 'admin'}), require('./canary/admin/app')());
|
|
|
|
|
|
|
|
apiApp.use(urlUtils.getVersionPath({version: 'canary', type: 'content'}), require('./canary/content/app')());
|
|
|
|
apiApp.use(urlUtils.getVersionPath({version: 'canary', type: 'admin'}), require('./canary/admin/app')());
|
|
|
|
|
|
|
|
// Error handling for requests to non-existent API versions
|
|
|
|
apiApp.use(errorHandler.resourceNotFound);
|
|
|
|
apiApp.use(errorHandler.handleJSONResponse);
|
|
|
|
|
|
|
|
debug('Parent API setup end');
|
|
|
|
return apiApp;
|
|
|
|
};
|