mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Renamed members ssr + api endpoints
This commit is contained in:
parent
fa4dfa1b21
commit
0cba02b370
4 changed files with 68 additions and 25 deletions
|
@ -73,7 +73,7 @@ Array.prototype.forEach.call(document.querySelectorAll('[data-members-plan]'), f
|
|||
errorEl.innerText = '';
|
||||
}
|
||||
el.classList.add('loading');
|
||||
fetch('{{blog-url}}/members/ssr', {
|
||||
fetch('{{blog-url}}/members/api/session', {
|
||||
credentials: 'same-origin'
|
||||
}).then(function (res) {
|
||||
if (!res.ok) {
|
||||
|
@ -143,7 +143,7 @@ Array.prototype.forEach.call(document.querySelectorAll('[data-members-edit-billi
|
|||
errorEl.innerText = '';
|
||||
}
|
||||
el.classList.add('loading');
|
||||
fetch('{{blog-url}}/members/ssr', {
|
||||
fetch('{{blog-url}}/members/api/session', {
|
||||
credentials: 'same-origin'
|
||||
}).then(function (res) {
|
||||
if (!res.ok) {
|
||||
|
@ -151,7 +151,7 @@ Array.prototype.forEach.call(document.querySelectorAll('[data-members-edit-billi
|
|||
}
|
||||
return res.text();
|
||||
}).then(function (identity) {
|
||||
return fetch('{{blog-url}}/members/api/create-stripe-setup-session/', {
|
||||
return fetch('{{blog-url}}/members/api/create-stripe-update-session/', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
|
@ -195,7 +195,7 @@ Array.prototype.forEach.call(document.querySelectorAll('[data-members-signout]')
|
|||
event.preventDefault();
|
||||
el.classList.remove('error');
|
||||
el.classList.add('loading');
|
||||
fetch('{{blog-url}}/members/ssr', {
|
||||
fetch('{{blog-url}}/members/api/session', {
|
||||
method: 'DELETE'
|
||||
}).then(function (res) {
|
||||
if (res.ok) {
|
||||
|
@ -224,7 +224,7 @@ Array.prototype.forEach.call(document.querySelectorAll('[data-members-cancel-sub
|
|||
errorEl.innerText = '';
|
||||
}
|
||||
|
||||
return fetch('{{blog-url}}/members/ssr', {
|
||||
return fetch('{{blog-url}}/members/api/session', {
|
||||
credentials: 'same-origin'
|
||||
}).then(function (res) {
|
||||
if (!res.ok) {
|
||||
|
@ -274,7 +274,7 @@ Array.prototype.forEach.call(document.querySelectorAll('[data-members-continue-s
|
|||
errorEl.innerText = '';
|
||||
}
|
||||
|
||||
return fetch('{{blog-url}}/members/ssr', {
|
||||
return fetch('{{blog-url}}/members/api/session', {
|
||||
credentials: 'same-origin'
|
||||
}).then(function (res) {
|
||||
if (!res.ok) {
|
||||
|
|
2
core/server/public/members.min.js
vendored
2
core/server/public/members.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -22,16 +22,19 @@ module.exports = function setupMembersApp() {
|
|||
membersApp.use(middleware.createSessionFromMagicLink);
|
||||
|
||||
// Routing
|
||||
// Initializes members specific routes as well as assigns members specific data to the req/res objects
|
||||
membersApp.get('/ssr/member', shared.middlewares.labs.members, middleware.getMemberData);
|
||||
membersApp.get('/ssr', shared.middlewares.labs.members, middleware.getIdentityToken);
|
||||
membersApp.delete('/ssr', shared.middlewares.labs.members, middleware.deleteSession);
|
||||
|
||||
// Webhooks
|
||||
membersApp.post('/webhooks/stripe', shared.middlewares.labs.members, middleware.stripeWebhooks);
|
||||
|
||||
// Initializes members specific routes as well as assigns members specific data to the req/res objects
|
||||
membersApp.get('/api/member', shared.middlewares.labs.members, middleware.getMemberData);
|
||||
membersApp.get('/api/session', shared.middlewares.labs.members, middleware.getIdentityToken);
|
||||
membersApp.delete('/api/session', shared.middlewares.labs.members, middleware.deleteSession);
|
||||
|
||||
// NOTE: this is wrapped in a function to ensure we always go via the getter
|
||||
membersApp.post('/api/send-magic-link', (req, res, next) => membersService.api.middleware.sendMagicLink(req, res, next));
|
||||
membersApp.post('/api/create-stripe-checkout-session', (req, res, next) => membersService.api.middleware.createCheckoutSession(req, res, next));
|
||||
membersApp.post('/api/create-stripe-setup-session', (req, res, next) => membersService.api.middleware.createCheckoutSetupSession(req, res, next));
|
||||
membersApp.post('/api/create-stripe-update-session', (req, res, next) => membersService.api.middleware.createCheckoutSetupSession(req, res, next));
|
||||
membersApp.put('/api/subscriptions/:id', (req, res, next) => membersService.api.middleware.updateSubscription(req, res, next));
|
||||
|
||||
// API error handling
|
||||
|
|
|
@ -45,23 +45,43 @@ describe('Basic Members Routes', function () {
|
|||
});
|
||||
|
||||
describe('Routes', function () {
|
||||
it('should error when invalid member token is passed in to ssr', function () {
|
||||
return request.get('/members/ssr')
|
||||
it('should error serving webhook endpoint without any parameters', function () {
|
||||
return request.post('/members/webhooks/stripe')
|
||||
.expect(400);
|
||||
});
|
||||
|
||||
it('should error when invalid member token is passed into session', function () {
|
||||
return request.get('/members/api/session')
|
||||
.expect(400);
|
||||
});
|
||||
|
||||
it('should return no content when removing member sessions', function () {
|
||||
return request.del('/members/ssr')
|
||||
return request.del('/members/api/session')
|
||||
.expect(204);
|
||||
});
|
||||
|
||||
it('should error for invalid member token on member data endpoint', function () {
|
||||
return request.get('/members/ssr/member')
|
||||
return request.get('/members/api/member')
|
||||
.expect(400);
|
||||
});
|
||||
|
||||
it('should error serving webhook endpoint without any parameters', function () {
|
||||
return request.post('/members/webhooks/stripe')
|
||||
it('should error for invalid data on member magic link endpoint', function () {
|
||||
return request.post('/members/api/send-magic-link')
|
||||
.expect(400);
|
||||
});
|
||||
|
||||
it('should error for invalid data on members create checkout session endpoint', function () {
|
||||
return request.post('/members/api/create-stripe-checkout-session')
|
||||
.expect(400);
|
||||
});
|
||||
|
||||
it('should error for invalid data on members create update session endpoint', function () {
|
||||
return request.post('/members/api/create-stripe-update-session')
|
||||
.expect(400);
|
||||
});
|
||||
|
||||
it('should error for invalid data on members subscription endpoint', function () {
|
||||
return request.put('/members/api/subscriptions/123')
|
||||
.expect(400);
|
||||
});
|
||||
});
|
||||
|
@ -92,23 +112,43 @@ describe('Basic Members Routes', function () {
|
|||
});
|
||||
|
||||
describe('Routes', function () {
|
||||
it('should not serve ssr endpoint', function () {
|
||||
return request.get('/members/ssr')
|
||||
it('should not serve webhook endpoint', function () {
|
||||
return request.post('/members/webhooks/stripe')
|
||||
.expect(404);
|
||||
});
|
||||
|
||||
it('should not serve ssr removal endpoint', function () {
|
||||
return request.del('/members/ssr')
|
||||
it('should not serve session endpoint', function () {
|
||||
return request.get('/members/api/session')
|
||||
.expect(404);
|
||||
});
|
||||
|
||||
it('should not serve session removal endpoint', function () {
|
||||
return request.del('/members/api/session')
|
||||
.expect(404);
|
||||
});
|
||||
|
||||
it('should not serve member data endpoint', function () {
|
||||
return request.get('/members/ssr/member')
|
||||
return request.get('/members/api/member')
|
||||
.expect(404);
|
||||
});
|
||||
|
||||
it('should not serve webhook endpoint', function () {
|
||||
return request.post('/members/webhooks/stripe')
|
||||
it('should not serve member magic link endpoint', function () {
|
||||
return request.post('/members/api/send-magic-link')
|
||||
.expect(404);
|
||||
});
|
||||
|
||||
it('should not serve members create checkout session endpoint', function () {
|
||||
return request.post('/members/api/create-stripe-checkout-session')
|
||||
.expect(404);
|
||||
});
|
||||
|
||||
it('should not serve members create update session endpoint', function () {
|
||||
return request.post('/members/api/create-stripe-update-session')
|
||||
.expect(404);
|
||||
});
|
||||
|
||||
it('should not serve members subscription endpoint', function () {
|
||||
return request.put('/members/api/subscriptions/123')
|
||||
.expect(404);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue