mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
parent
f33dacaf64
commit
f8d1e38290
5 changed files with 57 additions and 7 deletions
|
@ -64,7 +64,8 @@ function getPostData(req, res, next) {
|
|||
}
|
||||
|
||||
// @NOTE: amp is not supported for static pages
|
||||
helpers.entryLookup(urlWithoutSubdirectoryWithoutAmp, {permalinks, query: {controller: 'posts', resource: 'posts'}}, res.locals)
|
||||
// @TODO: AMP should make an HTTP request to the Content API {version}
|
||||
helpers.entryLookup(urlWithoutSubdirectoryWithoutAmp, {permalinks, query: {controller: 'postsPublic', resource: 'posts'}}, res.locals)
|
||||
.then((result) => {
|
||||
if (result && result.entry) {
|
||||
req.body.post = result.entry;
|
||||
|
|
|
@ -39,10 +39,12 @@ function entryLookup(postUrl, routerOptions, locals) {
|
|||
let options = {
|
||||
include: 'author,authors,tags'
|
||||
};
|
||||
|
||||
if (config.get('enableDeveloperExperiments')) {
|
||||
options.context = {member: locals.member};
|
||||
}
|
||||
return api[routerOptions.query.controller]
|
||||
|
||||
return (api[routerOptions.query.controller] || api[routerOptions.query.resource])
|
||||
.read(_.extend(_.pick(params, 'slug', 'id'), options))
|
||||
.then(function then(result) {
|
||||
const entry = result[routerOptions.query.resource][0];
|
||||
|
|
|
@ -4,6 +4,7 @@ const should = require('should'),
|
|||
cheerio = require('cheerio'),
|
||||
testUtils = require('../../utils'),
|
||||
configUtils = require('../../utils/configUtils'),
|
||||
appsService = require('../../../server/services/apps'),
|
||||
settingsService = require('../../../server/services/settings'),
|
||||
themeService = require('../../../server/services/themes'),
|
||||
siteApp = require('../../../server/web/parent-app');
|
||||
|
@ -20,7 +21,7 @@ describe('Integration - Web - Site', function () {
|
|||
|
||||
describe('default routes.yaml', function () {
|
||||
before(function () {
|
||||
testUtils.integrationTesting.defaultMocks(sinon);
|
||||
testUtils.integrationTesting.defaultMocks(sinon, {amp: true, apps: true});
|
||||
testUtils.integrationTesting.overrideGhostConfig(configUtils);
|
||||
|
||||
return testUtils.integrationTesting.initGhost()
|
||||
|
@ -30,6 +31,9 @@ describe('Integration - Web - Site', function () {
|
|||
|
||||
app = siteApp({start: true});
|
||||
return testUtils.integrationTesting.urlService.waitTillFinished();
|
||||
})
|
||||
.then(() => {
|
||||
return appsService.init();
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -64,6 +68,22 @@ describe('Integration - Web - Site', function () {
|
|||
});
|
||||
});
|
||||
|
||||
it('serve amp', function () {
|
||||
const req = {
|
||||
secure: true,
|
||||
method: 'GET',
|
||||
url: '/html-ipsum/amp/',
|
||||
host: 'example.com'
|
||||
};
|
||||
|
||||
return testUtils.mocks.express.invoke(app, req)
|
||||
.then(function (response) {
|
||||
response.statusCode.should.eql(200);
|
||||
response.template.should.match(/amp\.hbs/);
|
||||
response.body.should.match(/<h1>HTML Ipsum Presents<\/h1>/);
|
||||
});
|
||||
});
|
||||
|
||||
it('post not found', function () {
|
||||
const req = {
|
||||
secure: true,
|
||||
|
@ -1749,7 +1769,7 @@ describe('Integration - Web - Site', function () {
|
|||
describe('default routes.yaml', function () {
|
||||
before(function () {
|
||||
testUtils.integrationTesting.urlService.resetGenerators();
|
||||
testUtils.integrationTesting.defaultMocks(sinon);
|
||||
testUtils.integrationTesting.defaultMocks(sinon, {amp: true, apps: true});
|
||||
testUtils.integrationTesting.overrideGhostConfig(configUtils);
|
||||
|
||||
return testUtils.integrationTesting.initGhost()
|
||||
|
@ -1759,6 +1779,9 @@ describe('Integration - Web - Site', function () {
|
|||
|
||||
app = siteApp({start: true});
|
||||
return testUtils.integrationTesting.urlService.waitTillFinished();
|
||||
})
|
||||
.then(() => {
|
||||
return appsService.init();
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -1793,6 +1816,22 @@ describe('Integration - Web - Site', function () {
|
|||
});
|
||||
});
|
||||
|
||||
it('serve amp', function () {
|
||||
const req = {
|
||||
secure: true,
|
||||
method: 'GET',
|
||||
url: '/html-ipsum/amp/',
|
||||
host: 'example.com'
|
||||
};
|
||||
|
||||
return testUtils.mocks.express.invoke(app, req)
|
||||
.then(function (response) {
|
||||
response.statusCode.should.eql(200);
|
||||
response.template.should.match(/amp\.hbs/);
|
||||
response.body.should.match(/<h1>HTML Ipsum Presents<\/h1>/);
|
||||
});
|
||||
});
|
||||
|
||||
it('post not found', function () {
|
||||
const req = {
|
||||
secure: true,
|
||||
|
|
|
@ -122,7 +122,7 @@ describe('Unit - apps/amp/lib/router', function () {
|
|||
|
||||
urlService.getPermalinkByUrl.withArgs('/welcome/').returns('/:slug/');
|
||||
|
||||
helpers.entryLookup.withArgs('/welcome/', {permalinks: '/:slug/', query: {controller: 'posts', resource: 'posts'}})
|
||||
helpers.entryLookup.withArgs('/welcome/', {permalinks: '/:slug/', query: {controller: 'postsPublic', resource: 'posts'}})
|
||||
.resolves({
|
||||
entry: post
|
||||
});
|
||||
|
@ -139,7 +139,7 @@ describe('Unit - apps/amp/lib/router', function () {
|
|||
|
||||
urlService.getPermalinkByUrl.withArgs('/welcome/').returns('/:slug/');
|
||||
|
||||
helpers.entryLookup.withArgs('/welcome/', {permalinks: '/:slug/', query: {controller: 'posts', resource: 'posts'}}).resolves({
|
||||
helpers.entryLookup.withArgs('/welcome/', {permalinks: '/:slug/', query: {controller: 'postsPublic', resource: 'posts'}}).resolves({
|
||||
entry: post
|
||||
});
|
||||
|
||||
|
@ -154,7 +154,7 @@ describe('Unit - apps/amp/lib/router', function () {
|
|||
|
||||
urlService.getPermalinkByUrl.withArgs('/welcome/').returns('/:slug/');
|
||||
|
||||
helpers.entryLookup.withArgs('/welcome/', {permalinks: '/:slug/', query: {controller: 'posts', resource: 'posts'}})
|
||||
helpers.entryLookup.withArgs('/welcome/', {permalinks: '/:slug/', query: {controller: 'postsPublic', resource: 'posts'}})
|
||||
.rejects(new common.errors.NotFoundError());
|
||||
|
||||
ampController.getPostData(req, res, function (err) {
|
||||
|
|
|
@ -1052,6 +1052,14 @@ module.exports = {
|
|||
cacheStub.withArgs('permalinks').returns('/:slug/');
|
||||
cacheStub.withArgs('labs').returns({publicAPI: true});
|
||||
|
||||
if (options.amp) {
|
||||
cacheStub.withArgs('amp').returns(true);
|
||||
}
|
||||
|
||||
if (options.apps) {
|
||||
cacheStub.withArgs('active_apps').returns([]);
|
||||
}
|
||||
|
||||
sandbox.stub(api.clients, 'read').returns(Promise.resolve({
|
||||
clients: [
|
||||
{slug: 'ghost-frontend', secret: 'a1bcde23cfe5', status: 'enabled'}
|
||||
|
|
Loading…
Add table
Reference in a new issue