mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 11:55:03 +03:00
9c64d7af81
refs https://github.com/TryGhost/Team/issues/1420 - This changeset makes the "/ghost/api" base path for the APIs centralized in one place and reused by dependent modules. There are couple benefits this refactor brings: easy way to spot where the API base path is used (was hard to find it in regexp) and makes it easy to change the hardcoded path to a configurable one in the future (e.g. host all APIs under `domain.tld/custom-path/awesome-apis/posts`) - I hear that scream from the back of your head: "But hey! This introduced coupling to url-utils!". To that my unswer is: "No. This change only makes the coupling explicit, it's been there already and now can be addressed if we need to!". - A neat thing about his change, making the API work on a custom path is one line away, by moving the hardcoded `/ghost/api` to a config ;)
23 lines
766 B
JavaScript
23 lines
766 B
JavaScript
const debug = require('@tryghost/debug')('web:backend');
|
|
const express = require('../../../shared/express');
|
|
const {BASE_API_PATH} = require('../../../shared/url-utils');
|
|
|
|
/**
|
|
*
|
|
* @returns {import('express').RequestHandler}
|
|
*/
|
|
module.exports = () => {
|
|
debug('BackendApp setup start');
|
|
// BACKEND
|
|
// Wrap the admin and API apps into a single express app for use with vhost
|
|
const backendApp = express('backend');
|
|
|
|
backendApp.lazyUse(BASE_API_PATH, require('../api'));
|
|
backendApp.lazyUse('/ghost/oauth', require('../oauth'));
|
|
backendApp.lazyUse('/ghost/.well-known', require('../well-known'));
|
|
|
|
backendApp.use('/ghost', require('../../services/auth/session').createSessionFromToken, require('../admin')());
|
|
|
|
return backendApp;
|
|
};
|