2018-11-26 12:35:38 +03:00
|
|
|
const debug = require('ghost-ignition').debug('web:api:default:app');
|
|
|
|
const express = require('express');
|
2019-06-18 16:13:55 +03:00
|
|
|
const urlUtils = require('../../lib/url-utils');
|
2018-11-26 12:35:38 +03:00
|
|
|
const errorHandler = require('../shared/middlewares/error-handler');
|
2018-12-11 11:18:07 +03:00
|
|
|
const membersService = require('../../services/members');
|
|
|
|
|
2019-02-26 06:09:16 +03:00
|
|
|
const labs = require('../shared/middlewares/labs');
|
2018-11-26 12:35:38 +03:00
|
|
|
|
|
|
|
module.exports = function setupApiApp() {
|
|
|
|
debug('Parent API setup start');
|
|
|
|
const apiApp = express();
|
|
|
|
|
|
|
|
// Mount different API versions
|
|
|
|
apiApp.use(urlUtils.getVersionPath({version: 'v0.1'}), require('./v0.1/app')());
|
|
|
|
apiApp.use(urlUtils.getVersionPath({version: 'v2', type: 'content'}), require('./v2/content/app')());
|
|
|
|
apiApp.use(urlUtils.getVersionPath({version: 'v2', type: 'admin'}), require('./v2/admin/app')());
|
2019-02-26 06:09:16 +03:00
|
|
|
apiApp.use(urlUtils.getVersionPath({version: 'v2', type: 'members'}), labs.members, membersService.api.apiRouter);
|
2018-11-26 12:35:38 +03:00
|
|
|
|
|
|
|
// Error handling for requests to non-existent API versions
|
|
|
|
apiApp.use(errorHandler.resourceNotFound);
|
|
|
|
apiApp.use(errorHandler.handleJSONResponse);
|
|
|
|
|
|
|
|
debug('Parent API setup end');
|
|
|
|
return apiApp;
|
2019-06-18 16:13:55 +03:00
|
|
|
};
|