Moved members static pages to members api URL (#10887)

* Installed @tryghost/members-api@0.2.0

refs #10886

This will allow us to mount one router rather than having a static and
api router.

* Added members v2 api directory

refs #10886

This brings the members api more inline with how the rest of the apis
work within Ghost.

* Mounted the members api app to the api route

closes #10886

This successfully mounts the api and the static pages to the
/api/v2/members/ URL.

* Installed @tryghost/members-auth-pages@1.0.0

refs #10886

This updates the auth pages to work correctly with the new mount point.

* Changed membersUrl in members.js to use members api

refs #10886

This keeps the membersUrl lined up with the path for the static
members pages.

* Removed old members static mount point

refs #10886

These are no longer used, nor desired.

* Remove superfluous code from members service

refs #10886

This remove the gateway getter which is no longer used, and the fallback
for members not enabled - which is handled within the members app.

* Updated ssoOrigin to use admin url

refs #10886

This ensures that sites running on a separate admin domain have the
correct ssoOrigin, which is used to ensure only the designated auth
pages are used to hit the authentication endpoints.

Since the auth pages are now hosted under the `/ghost` url, they will be
on the admin origin and not the site origin
This commit is contained in:
Fabien O'Carroll 2019-07-09 19:02:44 +08:00 committed by GitHub
parent ce563179b8
commit 177411045a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 45 additions and 50 deletions

View File

@ -1 +1 @@
MembersThemeBindings.init({ssrUrl: "{{blog-url}}/members/ssr", membersUrl: "{{admin-url}}/members"});
MembersThemeBindings.init({ssrUrl: "{{blog-url}}/members/ssr", membersUrl: "{{admin-url}}/api/v2/members/static"});

View File

@ -116,6 +116,11 @@ const siteOrigin = doBlock(() => {
return `${protocol}//${host}`;
});
const adminOrigin = doBlock(() => {
const {protocol, host} = url.parse(urlUtils.urlFor('admin', true));
return `${protocol}//${host}`;
});
const getApiUrl = ({version, type}) => {
const {href} = new url.URL(
urlUtils.getApiPath({version, type}),
@ -180,7 +185,7 @@ const getSiteConfig = () => {
const membersApiInstance = MembersApi({
authConfig: {
issuer: membersApiUrl,
ssoOrigin: siteOrigin,
ssoOrigin: adminOrigin,
publicKey: settingsCache.get('members_public_key'),
privateKey: settingsCache.get('members_private_key'),
sessionSecret: settingsCache.get('members_session_secret'),

View File

@ -1,37 +1,9 @@
const config = require('../../config/index.js');
const common = require('../../lib/common');
module.exports = {
get api() {
if (!config.get('enableDeveloperExperiments')) {
return {
apiRouter: function (req, res, next) {
return next(new common.errors.NotFoundError());
},
staticRouter: function (req, res, next) {
return next(new common.errors.NotFoundError());
},
ssr: {
exchangeTokenForSession: function () {
return Promise.reject(new common.errors.InternalServerError());
},
deleteSession: function () {
return Promise.reject(new common.errors.InternalServerError());
},
getMemberDataFromSession: function () {
return Promise.reject(new common.errors.InternalServerError());
}
}
};
}
return require('./api');
},
get authPages() {
return require('./authPages');
},
get gateway() {
return require('./api').staticRouter;
}
};

View File

@ -2,9 +2,6 @@ const debug = require('ghost-ignition').debug('web:api:default:app');
const express = require('express');
const urlUtils = require('../../lib/url-utils');
const errorHandler = require('../shared/middlewares/error-handler');
const membersService = require('../../services/members');
const labs = require('../shared/middlewares/labs');
module.exports = function setupApiApp() {
debug('Parent API setup start');
@ -14,7 +11,7 @@ module.exports = function setupApiApp() {
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')());
apiApp.use(urlUtils.getVersionPath({version: 'v2', type: 'members'}), labs.members, membersService.api.apiRouter);
apiApp.use(urlUtils.getVersionPath({version: 'v2', type: 'members'}), require('./v2/members/app')());
// Error handling for requests to non-existent API versions
apiApp.use(errorHandler.resourceNotFound);

View File

@ -0,0 +1,27 @@
const debug = require('ghost-ignition').debug('web:v2:members:app');
const express = require('express');
const membersService = require('../../../../services/members');
const labs = require('../../../shared/middlewares/labs');
const shared = require('../../../shared');
module.exports = function setupMembersApiApp() {
debug('Members API v2 setup start');
const apiApp = express();
// Entire app is behind labs flag
apiApp.use(labs.members);
// Set up the auth pages
apiApp.use('/static/auth', membersService.authPages);
// Set up the api endpoints and the gateway
apiApp.use(membersService.api);
// API error handling
apiApp.use(shared.middlewares.errorHandler.resourceNotFound);
apiApp.use(shared.middlewares.errorHandler.handleJSONResponseV2);
debug('Members API v2 setup end');
return apiApp;
};

View File

@ -4,8 +4,6 @@ const config = require('../config');
const compress = require('compression');
const netjet = require('netjet');
const shared = require('./shared');
const labs = require('./shared/middlewares/labs');
const membersService = require('../services/members');
module.exports = function setupParentApp(options = {}) {
debug('ParentApp setup start');
@ -45,10 +43,6 @@ module.exports = function setupParentApp(options = {}) {
// @TODO: finish refactoring the API app
parentApp.use('/ghost/api', require('./api')());
// MEMBERS
parentApp.use('/ghost/members', labs.members, membersService.gateway);
parentApp.use('/ghost/members/auth', labs.members, membersService.authPages);
// ADMIN
parentApp.use('/ghost', require('./admin')());

View File

@ -41,8 +41,8 @@
"dependencies": {
"@nexes/nql": "0.2.2",
"@tryghost/helpers": "1.1.6",
"@tryghost/members-api": "0.1.2",
"@tryghost/members-auth-pages": "0.2.2",
"@tryghost/members-api": "0.2.0",
"@tryghost/members-auth-pages": "1.0.0",
"@tryghost/members-ssr": "0.1.5",
"@tryghost/members-theme-bindings": "0.2.1",
"@tryghost/social-urls": "0.1.0",

View File

@ -141,10 +141,10 @@
dependencies:
"@tryghost/kg-clean-basic-html" "^0.1.1"
"@tryghost/members-api@0.1.2":
version "0.1.2"
resolved "https://registry.yarnpkg.com/@tryghost/members-api/-/members-api-0.1.2.tgz#e7ef303e709d44d4f2dc0dda4f38af4f80c21c24"
integrity sha512-s8uKedgycszfRu3LH7ZTnLKk3CO099s+n+Kj0nljyb7thCqABiDGCSJ/Fxs72WxGGPVTtDB2WJAPGLkIe89TLQ==
"@tryghost/members-api@0.2.0":
version "0.2.0"
resolved "https://registry.yarnpkg.com/@tryghost/members-api/-/members-api-0.2.0.tgz#1f13dabc39015f8a5447a714dc05162426775027"
integrity sha512-fLTQylyUz16ZL0KJ4kBvWnUsQbq1NkLFXVkQjOEo/xFV1SG0iJBKlkVtPWfyncSHyGBSXAv9TcQymiT+9vr7pQ==
dependencies:
bluebird "^3.5.4"
body-parser "^1.19.0"
@ -155,10 +155,10 @@
lodash "^4.17.11"
node-jose "^1.1.3"
"@tryghost/members-auth-pages@0.2.2":
version "0.2.2"
resolved "https://registry.yarnpkg.com/@tryghost/members-auth-pages/-/members-auth-pages-0.2.2.tgz#c26db5afc8fbe676b1b3e3425ad819c42ee12134"
integrity sha512-Dbdz7KDG1cQAen5elNQr5+YwCmRbtAj6g6oGgIF6GjiBzMjtJp8E+Yx7fBAJ3stgkP3i5xLd3iQ+Bo/3h81IuA==
"@tryghost/members-auth-pages@1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@tryghost/members-auth-pages/-/members-auth-pages-1.0.0.tgz#9ba9bd6c608a68d782e8b7fd8c2939d8281386f9"
integrity sha512-N/NcSEParuV2dJ3WhGvvcwWLGJRha663l7Hs1XDlSKjAE06EsFlVb5uSSQdCLM27SWUXT0Irx8WKDSNa3J0v2A==
dependencies:
"@tryghost/members-gateway-protocol" "^0.1.2"
preact "^8.2.1"