✨Dynamic Routing Beta (#9596)
refs #9601
### Dynamic Routing
This is the beta version of dynamic routing.
- we had a initial implementation of "channels" available in the codebase
- we have removed and moved this implementation
- there is now a centralised place for dynamic routing - server/services/routing
- each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts
- keep as much as possible logic of routing helpers, middlewares and controllers
- ensure test coverage
- connect all the things together
- yaml file + validation
- routing + routers
- url service
- sitemaps
- url access
- deeper implementation of yaml validations
- e.g. hard require slashes
- ensure routing hierarchy/order
- e.g. you enable the subscriber app
- you have a custom static page, which lives under the same slug /subscribe
- static pages are stronger than apps
- e.g. the first collection owns the post it has filtered
- a post cannot live in two collections
- ensure apps are still working and hook into the routers layer (or better said: and register in the routing service)
- put as much as possible comments to the code base for better understanding
- ensure a clean debug log
- ensure we can unmount routes
- e.g. you have a collection permalink of /:slug/ represented by {globals.permalink}
- and you change the permalink in the admin to dated permalink
- the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/
- unmount without server restart, yey
- ensure we are backwards compatible
- e.g. render home.hbs for collection index if collection route is /
- ensure you can access your configured permalink from the settings table with {globals.permalink}
### Render 503 if url service did not finish
- return 503 if the url service has not finished generating the resource urls
### Rewrite sitemaps
- we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime
- we generate all urls on bootstrap
- the sitemaps service will consume created resource and router urls
- these urls will be shown on the xml pages
- we listen on url events
- we listen on router events
- we no longer have to fetch the resources, which is nice
- the urlservice pre-fetches resources and emits their urls
- the urlservice is the only component who knows which urls are valid
- i made some ES6 adaptions
- we keep the caching logic -> only regenerate xml if there is a change
- updated tests
- checked test coverage (100%)
### Re-work usage of Url utility
- replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId`
- only for resources e.g. post, author, tag
- this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime
- adapt url utility
- adapt tests
2018-06-05 19:02:20 +02:00
|
|
|
const should = require('should'),
|
|
|
|
sinon = require('sinon'),
|
|
|
|
Promise = require('bluebird'),
|
|
|
|
testUtils = require('../../../../utils'),
|
2020-03-30 16:26:47 +01:00
|
|
|
api = require('../../../../../core/server/api'),
|
|
|
|
helpers = require('../../../../../core/frontend/services/routing/helpers');
|
✨Dynamic Routing Beta (#9596)
refs #9601
### Dynamic Routing
This is the beta version of dynamic routing.
- we had a initial implementation of "channels" available in the codebase
- we have removed and moved this implementation
- there is now a centralised place for dynamic routing - server/services/routing
- each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts
- keep as much as possible logic of routing helpers, middlewares and controllers
- ensure test coverage
- connect all the things together
- yaml file + validation
- routing + routers
- url service
- sitemaps
- url access
- deeper implementation of yaml validations
- e.g. hard require slashes
- ensure routing hierarchy/order
- e.g. you enable the subscriber app
- you have a custom static page, which lives under the same slug /subscribe
- static pages are stronger than apps
- e.g. the first collection owns the post it has filtered
- a post cannot live in two collections
- ensure apps are still working and hook into the routers layer (or better said: and register in the routing service)
- put as much as possible comments to the code base for better understanding
- ensure a clean debug log
- ensure we can unmount routes
- e.g. you have a collection permalink of /:slug/ represented by {globals.permalink}
- and you change the permalink in the admin to dated permalink
- the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/
- unmount without server restart, yey
- ensure we are backwards compatible
- e.g. render home.hbs for collection index if collection route is /
- ensure you can access your configured permalink from the settings table with {globals.permalink}
### Render 503 if url service did not finish
- return 503 if the url service has not finished generating the resource urls
### Rewrite sitemaps
- we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime
- we generate all urls on bootstrap
- the sitemaps service will consume created resource and router urls
- these urls will be shown on the xml pages
- we listen on url events
- we listen on router events
- we no longer have to fetch the resources, which is nice
- the urlservice pre-fetches resources and emits their urls
- the urlservice is the only component who knows which urls are valid
- i made some ES6 adaptions
- we keep the caching logic -> only regenerate xml if there is a change
- updated tests
- checked test coverage (100%)
### Re-work usage of Url utility
- replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId`
- only for resources e.g. post, author, tag
- this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime
- adapt url utility
- adapt tests
2018-06-05 19:02:20 +02:00
|
|
|
|
2018-10-17 13:42:29 +02:00
|
|
|
describe('Unit - services/routing/helpers/entry-lookup', function () {
|
2018-10-17 09:23:59 +02:00
|
|
|
let posts, locals;
|
✨Dynamic Routing Beta (#9596)
refs #9601
### Dynamic Routing
This is the beta version of dynamic routing.
- we had a initial implementation of "channels" available in the codebase
- we have removed and moved this implementation
- there is now a centralised place for dynamic routing - server/services/routing
- each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts
- keep as much as possible logic of routing helpers, middlewares and controllers
- ensure test coverage
- connect all the things together
- yaml file + validation
- routing + routers
- url service
- sitemaps
- url access
- deeper implementation of yaml validations
- e.g. hard require slashes
- ensure routing hierarchy/order
- e.g. you enable the subscriber app
- you have a custom static page, which lives under the same slug /subscribe
- static pages are stronger than apps
- e.g. the first collection owns the post it has filtered
- a post cannot live in two collections
- ensure apps are still working and hook into the routers layer (or better said: and register in the routing service)
- put as much as possible comments to the code base for better understanding
- ensure a clean debug log
- ensure we can unmount routes
- e.g. you have a collection permalink of /:slug/ represented by {globals.permalink}
- and you change the permalink in the admin to dated permalink
- the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/
- unmount without server restart, yey
- ensure we are backwards compatible
- e.g. render home.hbs for collection index if collection route is /
- ensure you can access your configured permalink from the settings table with {globals.permalink}
### Render 503 if url service did not finish
- return 503 if the url service has not finished generating the resource urls
### Rewrite sitemaps
- we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime
- we generate all urls on bootstrap
- the sitemaps service will consume created resource and router urls
- these urls will be shown on the xml pages
- we listen on url events
- we listen on router events
- we no longer have to fetch the resources, which is nice
- the urlservice pre-fetches resources and emits their urls
- the urlservice is the only component who knows which urls are valid
- i made some ES6 adaptions
- we keep the caching logic -> only regenerate xml if there is a change
- updated tests
- checked test coverage (100%)
### Re-work usage of Url utility
- replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId`
- only for resources e.g. post, author, tag
- this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime
- adapt url utility
- adapt tests
2018-06-05 19:02:20 +02:00
|
|
|
|
|
|
|
afterEach(function () {
|
2019-01-21 17:53:44 +01:00
|
|
|
sinon.restore();
|
✨Dynamic Routing Beta (#9596)
refs #9601
### Dynamic Routing
This is the beta version of dynamic routing.
- we had a initial implementation of "channels" available in the codebase
- we have removed and moved this implementation
- there is now a centralised place for dynamic routing - server/services/routing
- each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts
- keep as much as possible logic of routing helpers, middlewares and controllers
- ensure test coverage
- connect all the things together
- yaml file + validation
- routing + routers
- url service
- sitemaps
- url access
- deeper implementation of yaml validations
- e.g. hard require slashes
- ensure routing hierarchy/order
- e.g. you enable the subscriber app
- you have a custom static page, which lives under the same slug /subscribe
- static pages are stronger than apps
- e.g. the first collection owns the post it has filtered
- a post cannot live in two collections
- ensure apps are still working and hook into the routers layer (or better said: and register in the routing service)
- put as much as possible comments to the code base for better understanding
- ensure a clean debug log
- ensure we can unmount routes
- e.g. you have a collection permalink of /:slug/ represented by {globals.permalink}
- and you change the permalink in the admin to dated permalink
- the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/
- unmount without server restart, yey
- ensure we are backwards compatible
- e.g. render home.hbs for collection index if collection route is /
- ensure you can access your configured permalink from the settings table with {globals.permalink}
### Render 503 if url service did not finish
- return 503 if the url service has not finished generating the resource urls
### Rewrite sitemaps
- we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime
- we generate all urls on bootstrap
- the sitemaps service will consume created resource and router urls
- these urls will be shown on the xml pages
- we listen on url events
- we listen on router events
- we no longer have to fetch the resources, which is nice
- the urlservice pre-fetches resources and emits their urls
- the urlservice is the only component who knows which urls are valid
- i made some ES6 adaptions
- we keep the caching logic -> only regenerate xml if there is a change
- updated tests
- checked test coverage (100%)
### Re-work usage of Url utility
- replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId`
- only for resources e.g. post, author, tag
- this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime
- adapt url utility
- adapt tests
2018-06-05 19:02:20 +02:00
|
|
|
});
|
|
|
|
|
2018-10-17 14:22:33 +02:00
|
|
|
describe('v2', function () {
|
|
|
|
describe('static pages', function () {
|
|
|
|
const routerOptions = {
|
|
|
|
permalinks: '/:slug/',
|
2019-02-22 04:17:14 +01:00
|
|
|
query: {controller: 'pagesPublic', resource: 'pages'}
|
2018-10-17 14:22:33 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
let pages;
|
|
|
|
let postsReadStub;
|
|
|
|
let pagesReadStub;
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
pages = [
|
|
|
|
testUtils.DataGenerator.forKnex.createPost({url: '/test/', slug: 'test', page: true})
|
|
|
|
];
|
|
|
|
|
2019-01-21 17:53:44 +01:00
|
|
|
postsReadStub = sinon.stub();
|
|
|
|
pagesReadStub = sinon.stub();
|
2018-10-17 14:22:33 +02:00
|
|
|
|
2019-02-25 17:03:27 +01:00
|
|
|
pagesReadStub//.withArgs({slug: pages[0].slug, include: 'author,authors,tags'})
|
2018-10-17 14:22:33 +02:00
|
|
|
.resolves({
|
|
|
|
pages: pages
|
|
|
|
});
|
|
|
|
|
2019-01-21 17:53:44 +01:00
|
|
|
sinon.stub(api.v2, 'posts').get(() => {
|
2018-10-17 14:22:33 +02:00
|
|
|
return {
|
|
|
|
read: postsReadStub
|
|
|
|
};
|
|
|
|
});
|
✨Dynamic Routing Beta (#9596)
refs #9601
### Dynamic Routing
This is the beta version of dynamic routing.
- we had a initial implementation of "channels" available in the codebase
- we have removed and moved this implementation
- there is now a centralised place for dynamic routing - server/services/routing
- each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts
- keep as much as possible logic of routing helpers, middlewares and controllers
- ensure test coverage
- connect all the things together
- yaml file + validation
- routing + routers
- url service
- sitemaps
- url access
- deeper implementation of yaml validations
- e.g. hard require slashes
- ensure routing hierarchy/order
- e.g. you enable the subscriber app
- you have a custom static page, which lives under the same slug /subscribe
- static pages are stronger than apps
- e.g. the first collection owns the post it has filtered
- a post cannot live in two collections
- ensure apps are still working and hook into the routers layer (or better said: and register in the routing service)
- put as much as possible comments to the code base for better understanding
- ensure a clean debug log
- ensure we can unmount routes
- e.g. you have a collection permalink of /:slug/ represented by {globals.permalink}
- and you change the permalink in the admin to dated permalink
- the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/
- unmount without server restart, yey
- ensure we are backwards compatible
- e.g. render home.hbs for collection index if collection route is /
- ensure you can access your configured permalink from the settings table with {globals.permalink}
### Render 503 if url service did not finish
- return 503 if the url service has not finished generating the resource urls
### Rewrite sitemaps
- we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime
- we generate all urls on bootstrap
- the sitemaps service will consume created resource and router urls
- these urls will be shown on the xml pages
- we listen on url events
- we listen on router events
- we no longer have to fetch the resources, which is nice
- the urlservice pre-fetches resources and emits their urls
- the urlservice is the only component who knows which urls are valid
- i made some ES6 adaptions
- we keep the caching logic -> only regenerate xml if there is a change
- updated tests
- checked test coverage (100%)
### Re-work usage of Url utility
- replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId`
- only for resources e.g. post, author, tag
- this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime
- adapt url utility
- adapt tests
2018-06-05 19:02:20 +02:00
|
|
|
|
2019-02-22 04:17:14 +01:00
|
|
|
sinon.stub(api.v2, 'pagesPublic').get(() => {
|
2018-10-17 14:22:33 +02:00
|
|
|
return {
|
|
|
|
read: pagesReadStub
|
|
|
|
};
|
|
|
|
});
|
✨Dynamic Routing Beta (#9596)
refs #9601
### Dynamic Routing
This is the beta version of dynamic routing.
- we had a initial implementation of "channels" available in the codebase
- we have removed and moved this implementation
- there is now a centralised place for dynamic routing - server/services/routing
- each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts
- keep as much as possible logic of routing helpers, middlewares and controllers
- ensure test coverage
- connect all the things together
- yaml file + validation
- routing + routers
- url service
- sitemaps
- url access
- deeper implementation of yaml validations
- e.g. hard require slashes
- ensure routing hierarchy/order
- e.g. you enable the subscriber app
- you have a custom static page, which lives under the same slug /subscribe
- static pages are stronger than apps
- e.g. the first collection owns the post it has filtered
- a post cannot live in two collections
- ensure apps are still working and hook into the routers layer (or better said: and register in the routing service)
- put as much as possible comments to the code base for better understanding
- ensure a clean debug log
- ensure we can unmount routes
- e.g. you have a collection permalink of /:slug/ represented by {globals.permalink}
- and you change the permalink in the admin to dated permalink
- the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/
- unmount without server restart, yey
- ensure we are backwards compatible
- e.g. render home.hbs for collection index if collection route is /
- ensure you can access your configured permalink from the settings table with {globals.permalink}
### Render 503 if url service did not finish
- return 503 if the url service has not finished generating the resource urls
### Rewrite sitemaps
- we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime
- we generate all urls on bootstrap
- the sitemaps service will consume created resource and router urls
- these urls will be shown on the xml pages
- we listen on url events
- we listen on router events
- we no longer have to fetch the resources, which is nice
- the urlservice pre-fetches resources and emits their urls
- the urlservice is the only component who knows which urls are valid
- i made some ES6 adaptions
- we keep the caching logic -> only regenerate xml if there is a change
- updated tests
- checked test coverage (100%)
### Re-work usage of Url utility
- replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId`
- only for resources e.g. post, author, tag
- this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime
- adapt url utility
- adapt tests
2018-06-05 19:02:20 +02:00
|
|
|
|
2018-10-17 14:22:33 +02:00
|
|
|
locals = {apiVersion: 'v2'};
|
|
|
|
});
|
✨Dynamic Routing Beta (#9596)
refs #9601
### Dynamic Routing
This is the beta version of dynamic routing.
- we had a initial implementation of "channels" available in the codebase
- we have removed and moved this implementation
- there is now a centralised place for dynamic routing - server/services/routing
- each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts
- keep as much as possible logic of routing helpers, middlewares and controllers
- ensure test coverage
- connect all the things together
- yaml file + validation
- routing + routers
- url service
- sitemaps
- url access
- deeper implementation of yaml validations
- e.g. hard require slashes
- ensure routing hierarchy/order
- e.g. you enable the subscriber app
- you have a custom static page, which lives under the same slug /subscribe
- static pages are stronger than apps
- e.g. the first collection owns the post it has filtered
- a post cannot live in two collections
- ensure apps are still working and hook into the routers layer (or better said: and register in the routing service)
- put as much as possible comments to the code base for better understanding
- ensure a clean debug log
- ensure we can unmount routes
- e.g. you have a collection permalink of /:slug/ represented by {globals.permalink}
- and you change the permalink in the admin to dated permalink
- the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/
- unmount without server restart, yey
- ensure we are backwards compatible
- e.g. render home.hbs for collection index if collection route is /
- ensure you can access your configured permalink from the settings table with {globals.permalink}
### Render 503 if url service did not finish
- return 503 if the url service has not finished generating the resource urls
### Rewrite sitemaps
- we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime
- we generate all urls on bootstrap
- the sitemaps service will consume created resource and router urls
- these urls will be shown on the xml pages
- we listen on url events
- we listen on router events
- we no longer have to fetch the resources, which is nice
- the urlservice pre-fetches resources and emits their urls
- the urlservice is the only component who knows which urls are valid
- i made some ES6 adaptions
- we keep the caching logic -> only regenerate xml if there is a change
- updated tests
- checked test coverage (100%)
### Re-work usage of Url utility
- replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId`
- only for resources e.g. post, author, tag
- this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime
- adapt url utility
- adapt tests
2018-06-05 19:02:20 +02:00
|
|
|
|
2018-10-17 14:22:33 +02:00
|
|
|
it('ensure pages controller is triggered', function () {
|
|
|
|
const testUrl = 'http://127.0.0.1:2369' + pages[0].url;
|
|
|
|
|
|
|
|
return helpers.entryLookup(testUrl, routerOptions, locals).then(function (lookup) {
|
|
|
|
postsReadStub.called.should.be.false();
|
|
|
|
pagesReadStub.calledOnce.should.be.true();
|
|
|
|
should.exist(lookup.entry);
|
|
|
|
lookup.entry.should.have.property('url', pages[0].url);
|
|
|
|
lookup.isEditURL.should.be.false();
|
|
|
|
});
|
|
|
|
});
|
✨Dynamic Routing Beta (#9596)
refs #9601
### Dynamic Routing
This is the beta version of dynamic routing.
- we had a initial implementation of "channels" available in the codebase
- we have removed and moved this implementation
- there is now a centralised place for dynamic routing - server/services/routing
- each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts
- keep as much as possible logic of routing helpers, middlewares and controllers
- ensure test coverage
- connect all the things together
- yaml file + validation
- routing + routers
- url service
- sitemaps
- url access
- deeper implementation of yaml validations
- e.g. hard require slashes
- ensure routing hierarchy/order
- e.g. you enable the subscriber app
- you have a custom static page, which lives under the same slug /subscribe
- static pages are stronger than apps
- e.g. the first collection owns the post it has filtered
- a post cannot live in two collections
- ensure apps are still working and hook into the routers layer (or better said: and register in the routing service)
- put as much as possible comments to the code base for better understanding
- ensure a clean debug log
- ensure we can unmount routes
- e.g. you have a collection permalink of /:slug/ represented by {globals.permalink}
- and you change the permalink in the admin to dated permalink
- the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/
- unmount without server restart, yey
- ensure we are backwards compatible
- e.g. render home.hbs for collection index if collection route is /
- ensure you can access your configured permalink from the settings table with {globals.permalink}
### Render 503 if url service did not finish
- return 503 if the url service has not finished generating the resource urls
### Rewrite sitemaps
- we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime
- we generate all urls on bootstrap
- the sitemaps service will consume created resource and router urls
- these urls will be shown on the xml pages
- we listen on url events
- we listen on router events
- we no longer have to fetch the resources, which is nice
- the urlservice pre-fetches resources and emits their urls
- the urlservice is the only component who knows which urls are valid
- i made some ES6 adaptions
- we keep the caching logic -> only regenerate xml if there is a change
- updated tests
- checked test coverage (100%)
### Re-work usage of Url utility
- replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId`
- only for resources e.g. post, author, tag
- this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime
- adapt url utility
- adapt tests
2018-06-05 19:02:20 +02:00
|
|
|
});
|
|
|
|
|
2018-10-17 14:22:33 +02:00
|
|
|
describe('posts', function () {
|
|
|
|
const routerOptions = {
|
|
|
|
permalinks: '/:slug/',
|
2019-01-04 21:59:39 +01:00
|
|
|
query: {controller: 'posts', resource: 'posts'}
|
2018-10-17 14:22:33 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
let posts;
|
|
|
|
let postsReadStub;
|
|
|
|
let pagesReadStub;
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
posts = [
|
|
|
|
testUtils.DataGenerator.forKnex.createPost({url: '/test/', slug: 'test'})
|
|
|
|
];
|
|
|
|
|
2019-01-21 17:53:44 +01:00
|
|
|
postsReadStub = sinon.stub();
|
|
|
|
pagesReadStub = sinon.stub();
|
2018-10-17 14:22:33 +02:00
|
|
|
|
2019-02-25 17:03:27 +01:00
|
|
|
postsReadStub//.withArgs({slug: posts[0].slug, include: 'author,authors,tags'})
|
2018-10-17 14:22:33 +02:00
|
|
|
.resolves({
|
|
|
|
posts: posts
|
|
|
|
});
|
|
|
|
|
2019-01-21 17:53:44 +01:00
|
|
|
sinon.stub(api.v2, 'posts').get(() => {
|
2018-10-17 14:22:33 +02:00
|
|
|
return {
|
|
|
|
read: postsReadStub
|
|
|
|
};
|
|
|
|
});
|
✨Dynamic Routing Beta (#9596)
refs #9601
### Dynamic Routing
This is the beta version of dynamic routing.
- we had a initial implementation of "channels" available in the codebase
- we have removed and moved this implementation
- there is now a centralised place for dynamic routing - server/services/routing
- each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts
- keep as much as possible logic of routing helpers, middlewares and controllers
- ensure test coverage
- connect all the things together
- yaml file + validation
- routing + routers
- url service
- sitemaps
- url access
- deeper implementation of yaml validations
- e.g. hard require slashes
- ensure routing hierarchy/order
- e.g. you enable the subscriber app
- you have a custom static page, which lives under the same slug /subscribe
- static pages are stronger than apps
- e.g. the first collection owns the post it has filtered
- a post cannot live in two collections
- ensure apps are still working and hook into the routers layer (or better said: and register in the routing service)
- put as much as possible comments to the code base for better understanding
- ensure a clean debug log
- ensure we can unmount routes
- e.g. you have a collection permalink of /:slug/ represented by {globals.permalink}
- and you change the permalink in the admin to dated permalink
- the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/
- unmount without server restart, yey
- ensure we are backwards compatible
- e.g. render home.hbs for collection index if collection route is /
- ensure you can access your configured permalink from the settings table with {globals.permalink}
### Render 503 if url service did not finish
- return 503 if the url service has not finished generating the resource urls
### Rewrite sitemaps
- we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime
- we generate all urls on bootstrap
- the sitemaps service will consume created resource and router urls
- these urls will be shown on the xml pages
- we listen on url events
- we listen on router events
- we no longer have to fetch the resources, which is nice
- the urlservice pre-fetches resources and emits their urls
- the urlservice is the only component who knows which urls are valid
- i made some ES6 adaptions
- we keep the caching logic -> only regenerate xml if there is a change
- updated tests
- checked test coverage (100%)
### Re-work usage of Url utility
- replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId`
- only for resources e.g. post, author, tag
- this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime
- adapt url utility
- adapt tests
2018-06-05 19:02:20 +02:00
|
|
|
|
2019-02-22 04:17:14 +01:00
|
|
|
sinon.stub(api.v2, 'pagesPublic').get(() => {
|
2018-10-17 14:22:33 +02:00
|
|
|
return {
|
|
|
|
read: pagesReadStub
|
|
|
|
};
|
|
|
|
});
|
✨Dynamic Routing Beta (#9596)
refs #9601
### Dynamic Routing
This is the beta version of dynamic routing.
- we had a initial implementation of "channels" available in the codebase
- we have removed and moved this implementation
- there is now a centralised place for dynamic routing - server/services/routing
- each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts
- keep as much as possible logic of routing helpers, middlewares and controllers
- ensure test coverage
- connect all the things together
- yaml file + validation
- routing + routers
- url service
- sitemaps
- url access
- deeper implementation of yaml validations
- e.g. hard require slashes
- ensure routing hierarchy/order
- e.g. you enable the subscriber app
- you have a custom static page, which lives under the same slug /subscribe
- static pages are stronger than apps
- e.g. the first collection owns the post it has filtered
- a post cannot live in two collections
- ensure apps are still working and hook into the routers layer (or better said: and register in the routing service)
- put as much as possible comments to the code base for better understanding
- ensure a clean debug log
- ensure we can unmount routes
- e.g. you have a collection permalink of /:slug/ represented by {globals.permalink}
- and you change the permalink in the admin to dated permalink
- the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/
- unmount without server restart, yey
- ensure we are backwards compatible
- e.g. render home.hbs for collection index if collection route is /
- ensure you can access your configured permalink from the settings table with {globals.permalink}
### Render 503 if url service did not finish
- return 503 if the url service has not finished generating the resource urls
### Rewrite sitemaps
- we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime
- we generate all urls on bootstrap
- the sitemaps service will consume created resource and router urls
- these urls will be shown on the xml pages
- we listen on url events
- we listen on router events
- we no longer have to fetch the resources, which is nice
- the urlservice pre-fetches resources and emits their urls
- the urlservice is the only component who knows which urls are valid
- i made some ES6 adaptions
- we keep the caching logic -> only regenerate xml if there is a change
- updated tests
- checked test coverage (100%)
### Re-work usage of Url utility
- replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId`
- only for resources e.g. post, author, tag
- this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime
- adapt url utility
- adapt tests
2018-06-05 19:02:20 +02:00
|
|
|
|
2018-10-17 14:22:33 +02:00
|
|
|
locals = {apiVersion: 'v2'};
|
|
|
|
});
|
✨Dynamic Routing Beta (#9596)
refs #9601
### Dynamic Routing
This is the beta version of dynamic routing.
- we had a initial implementation of "channels" available in the codebase
- we have removed and moved this implementation
- there is now a centralised place for dynamic routing - server/services/routing
- each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts
- keep as much as possible logic of routing helpers, middlewares and controllers
- ensure test coverage
- connect all the things together
- yaml file + validation
- routing + routers
- url service
- sitemaps
- url access
- deeper implementation of yaml validations
- e.g. hard require slashes
- ensure routing hierarchy/order
- e.g. you enable the subscriber app
- you have a custom static page, which lives under the same slug /subscribe
- static pages are stronger than apps
- e.g. the first collection owns the post it has filtered
- a post cannot live in two collections
- ensure apps are still working and hook into the routers layer (or better said: and register in the routing service)
- put as much as possible comments to the code base for better understanding
- ensure a clean debug log
- ensure we can unmount routes
- e.g. you have a collection permalink of /:slug/ represented by {globals.permalink}
- and you change the permalink in the admin to dated permalink
- the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/
- unmount without server restart, yey
- ensure we are backwards compatible
- e.g. render home.hbs for collection index if collection route is /
- ensure you can access your configured permalink from the settings table with {globals.permalink}
### Render 503 if url service did not finish
- return 503 if the url service has not finished generating the resource urls
### Rewrite sitemaps
- we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime
- we generate all urls on bootstrap
- the sitemaps service will consume created resource and router urls
- these urls will be shown on the xml pages
- we listen on url events
- we listen on router events
- we no longer have to fetch the resources, which is nice
- the urlservice pre-fetches resources and emits their urls
- the urlservice is the only component who knows which urls are valid
- i made some ES6 adaptions
- we keep the caching logic -> only regenerate xml if there is a change
- updated tests
- checked test coverage (100%)
### Re-work usage of Url utility
- replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId`
- only for resources e.g. post, author, tag
- this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime
- adapt url utility
- adapt tests
2018-06-05 19:02:20 +02:00
|
|
|
|
2018-10-17 14:22:33 +02:00
|
|
|
it('ensure posts controller is triggered', function () {
|
|
|
|
const testUrl = 'http://127.0.0.1:2369' + posts[0].url;
|
|
|
|
|
|
|
|
return helpers.entryLookup(testUrl, routerOptions, locals).then(function (lookup) {
|
|
|
|
postsReadStub.calledOnce.should.be.true();
|
|
|
|
pagesReadStub.called.should.be.false();
|
|
|
|
should.exist(lookup.entry);
|
|
|
|
lookup.entry.should.have.property('url', posts[0].url);
|
|
|
|
lookup.isEditURL.should.be.false();
|
|
|
|
});
|
|
|
|
});
|
✨Dynamic Routing Beta (#9596)
refs #9601
### Dynamic Routing
This is the beta version of dynamic routing.
- we had a initial implementation of "channels" available in the codebase
- we have removed and moved this implementation
- there is now a centralised place for dynamic routing - server/services/routing
- each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts
- keep as much as possible logic of routing helpers, middlewares and controllers
- ensure test coverage
- connect all the things together
- yaml file + validation
- routing + routers
- url service
- sitemaps
- url access
- deeper implementation of yaml validations
- e.g. hard require slashes
- ensure routing hierarchy/order
- e.g. you enable the subscriber app
- you have a custom static page, which lives under the same slug /subscribe
- static pages are stronger than apps
- e.g. the first collection owns the post it has filtered
- a post cannot live in two collections
- ensure apps are still working and hook into the routers layer (or better said: and register in the routing service)
- put as much as possible comments to the code base for better understanding
- ensure a clean debug log
- ensure we can unmount routes
- e.g. you have a collection permalink of /:slug/ represented by {globals.permalink}
- and you change the permalink in the admin to dated permalink
- the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/
- unmount without server restart, yey
- ensure we are backwards compatible
- e.g. render home.hbs for collection index if collection route is /
- ensure you can access your configured permalink from the settings table with {globals.permalink}
### Render 503 if url service did not finish
- return 503 if the url service has not finished generating the resource urls
### Rewrite sitemaps
- we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime
- we generate all urls on bootstrap
- the sitemaps service will consume created resource and router urls
- these urls will be shown on the xml pages
- we listen on url events
- we listen on router events
- we no longer have to fetch the resources, which is nice
- the urlservice pre-fetches resources and emits their urls
- the urlservice is the only component who knows which urls are valid
- i made some ES6 adaptions
- we keep the caching logic -> only regenerate xml if there is a change
- updated tests
- checked test coverage (100%)
### Re-work usage of Url utility
- replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId`
- only for resources e.g. post, author, tag
- this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime
- adapt url utility
- adapt tests
2018-06-05 19:02:20 +02:00
|
|
|
});
|
|
|
|
});
|
2019-08-09 19:55:12 +05:30
|
|
|
|
|
|
|
describe('canary', function () {
|
|
|
|
describe('static pages', function () {
|
|
|
|
const routerOptions = {
|
|
|
|
permalinks: '/:slug/',
|
|
|
|
query: {controller: 'pagesPublic', resource: 'pages'}
|
|
|
|
};
|
|
|
|
|
|
|
|
let pages;
|
|
|
|
let postsReadStub;
|
|
|
|
let pagesReadStub;
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
pages = [
|
|
|
|
testUtils.DataGenerator.forKnex.createPost({url: '/test/', slug: 'test', page: true})
|
|
|
|
];
|
|
|
|
|
|
|
|
postsReadStub = sinon.stub();
|
|
|
|
pagesReadStub = sinon.stub();
|
|
|
|
|
|
|
|
pagesReadStub//.withArgs({slug: pages[0].slug, include: 'author,authors,tags'})
|
|
|
|
.resolves({
|
|
|
|
pages: pages
|
|
|
|
});
|
|
|
|
|
|
|
|
sinon.stub(api.canary, 'posts').get(() => {
|
|
|
|
return {
|
|
|
|
read: postsReadStub
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
sinon.stub(api.canary, 'pagesPublic').get(() => {
|
|
|
|
return {
|
|
|
|
read: pagesReadStub
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
locals = {apiVersion: 'canary'};
|
|
|
|
});
|
|
|
|
|
|
|
|
it('ensure pages controller is triggered', function () {
|
|
|
|
const testUrl = 'http://127.0.0.1:2369' + pages[0].url;
|
|
|
|
|
|
|
|
return helpers.entryLookup(testUrl, routerOptions, locals).then(function (lookup) {
|
|
|
|
postsReadStub.called.should.be.false();
|
|
|
|
pagesReadStub.calledOnce.should.be.true();
|
|
|
|
should.exist(lookup.entry);
|
|
|
|
lookup.entry.should.have.property('url', pages[0].url);
|
|
|
|
lookup.isEditURL.should.be.false();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('posts', function () {
|
|
|
|
const routerOptions = {
|
|
|
|
permalinks: '/:slug/',
|
|
|
|
query: {controller: 'posts', resource: 'posts'}
|
|
|
|
};
|
|
|
|
|
|
|
|
let posts;
|
|
|
|
let postsReadStub;
|
|
|
|
let pagesReadStub;
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
posts = [
|
|
|
|
testUtils.DataGenerator.forKnex.createPost({url: '/test/', slug: 'test'})
|
|
|
|
];
|
|
|
|
|
|
|
|
postsReadStub = sinon.stub();
|
|
|
|
pagesReadStub = sinon.stub();
|
|
|
|
|
|
|
|
postsReadStub//.withArgs({slug: posts[0].slug, include: 'author,authors,tags'})
|
|
|
|
.resolves({
|
|
|
|
posts: posts
|
|
|
|
});
|
|
|
|
|
|
|
|
sinon.stub(api.canary, 'posts').get(() => {
|
|
|
|
return {
|
|
|
|
read: postsReadStub
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
sinon.stub(api.canary, 'pagesPublic').get(() => {
|
|
|
|
return {
|
|
|
|
read: pagesReadStub
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
locals = {apiVersion: 'canary'};
|
|
|
|
});
|
|
|
|
|
|
|
|
it('ensure posts controller is triggered', function () {
|
|
|
|
const testUrl = 'http://127.0.0.1:2369' + posts[0].url;
|
|
|
|
|
|
|
|
return helpers.entryLookup(testUrl, routerOptions, locals).then(function (lookup) {
|
|
|
|
postsReadStub.calledOnce.should.be.true();
|
|
|
|
pagesReadStub.called.should.be.false();
|
|
|
|
should.exist(lookup.entry);
|
|
|
|
lookup.entry.should.have.property('url', posts[0].url);
|
|
|
|
lookup.isEditURL.should.be.false();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2019-09-03 12:33:31 +05:30
|
|
|
|
|
|
|
describe('v3', function () {
|
|
|
|
describe('static pages', function () {
|
|
|
|
const routerOptions = {
|
|
|
|
permalinks: '/:slug/',
|
|
|
|
query: {controller: 'pagesPublic', resource: 'pages'}
|
|
|
|
};
|
|
|
|
|
|
|
|
let pages;
|
|
|
|
let postsReadStub;
|
|
|
|
let pagesReadStub;
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
pages = [
|
|
|
|
testUtils.DataGenerator.forKnex.createPost({url: '/test/', slug: 'test', page: true})
|
|
|
|
];
|
|
|
|
|
|
|
|
postsReadStub = sinon.stub();
|
|
|
|
pagesReadStub = sinon.stub();
|
|
|
|
|
|
|
|
pagesReadStub//.withArgs({slug: pages[0].slug, include: 'author,authors,tags'})
|
|
|
|
.resolves({
|
|
|
|
pages: pages
|
|
|
|
});
|
|
|
|
|
|
|
|
sinon.stub(api.v3, 'posts').get(() => {
|
|
|
|
return {
|
|
|
|
read: postsReadStub
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
sinon.stub(api.v3, 'pagesPublic').get(() => {
|
|
|
|
return {
|
|
|
|
read: pagesReadStub
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
locals = {apiVersion: 'v3'};
|
|
|
|
});
|
|
|
|
|
|
|
|
it('ensure pages controller is triggered', function () {
|
|
|
|
const testUrl = 'http://127.0.0.1:2369' + pages[0].url;
|
|
|
|
|
|
|
|
return helpers.entryLookup(testUrl, routerOptions, locals).then(function (lookup) {
|
|
|
|
postsReadStub.called.should.be.false();
|
|
|
|
pagesReadStub.calledOnce.should.be.true();
|
|
|
|
should.exist(lookup.entry);
|
|
|
|
lookup.entry.should.have.property('url', pages[0].url);
|
|
|
|
lookup.isEditURL.should.be.false();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('posts', function () {
|
|
|
|
const routerOptions = {
|
|
|
|
permalinks: '/:slug/',
|
|
|
|
query: {controller: 'posts', resource: 'posts'}
|
|
|
|
};
|
|
|
|
|
|
|
|
let posts;
|
|
|
|
let postsReadStub;
|
|
|
|
let pagesReadStub;
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
posts = [
|
|
|
|
testUtils.DataGenerator.forKnex.createPost({url: '/test/', slug: 'test'})
|
|
|
|
];
|
|
|
|
|
|
|
|
postsReadStub = sinon.stub();
|
|
|
|
pagesReadStub = sinon.stub();
|
|
|
|
|
|
|
|
postsReadStub//.withArgs({slug: posts[0].slug, include: 'author,authors,tags'})
|
|
|
|
.resolves({
|
|
|
|
posts: posts
|
|
|
|
});
|
|
|
|
|
|
|
|
sinon.stub(api.v3, 'posts').get(() => {
|
|
|
|
return {
|
|
|
|
read: postsReadStub
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
sinon.stub(api.v3, 'pagesPublic').get(() => {
|
|
|
|
return {
|
|
|
|
read: pagesReadStub
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
locals = {apiVersion: 'v3'};
|
|
|
|
});
|
|
|
|
|
|
|
|
it('ensure posts controller is triggered', function () {
|
|
|
|
const testUrl = 'http://127.0.0.1:2369' + posts[0].url;
|
|
|
|
|
|
|
|
return helpers.entryLookup(testUrl, routerOptions, locals).then(function (lookup) {
|
|
|
|
postsReadStub.calledOnce.should.be.true();
|
|
|
|
pagesReadStub.called.should.be.false();
|
|
|
|
should.exist(lookup.entry);
|
|
|
|
lookup.entry.should.have.property('url', posts[0].url);
|
|
|
|
lookup.isEditURL.should.be.false();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
✨Dynamic Routing Beta (#9596)
refs #9601
### Dynamic Routing
This is the beta version of dynamic routing.
- we had a initial implementation of "channels" available in the codebase
- we have removed and moved this implementation
- there is now a centralised place for dynamic routing - server/services/routing
- each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts
- keep as much as possible logic of routing helpers, middlewares and controllers
- ensure test coverage
- connect all the things together
- yaml file + validation
- routing + routers
- url service
- sitemaps
- url access
- deeper implementation of yaml validations
- e.g. hard require slashes
- ensure routing hierarchy/order
- e.g. you enable the subscriber app
- you have a custom static page, which lives under the same slug /subscribe
- static pages are stronger than apps
- e.g. the first collection owns the post it has filtered
- a post cannot live in two collections
- ensure apps are still working and hook into the routers layer (or better said: and register in the routing service)
- put as much as possible comments to the code base for better understanding
- ensure a clean debug log
- ensure we can unmount routes
- e.g. you have a collection permalink of /:slug/ represented by {globals.permalink}
- and you change the permalink in the admin to dated permalink
- the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/
- unmount without server restart, yey
- ensure we are backwards compatible
- e.g. render home.hbs for collection index if collection route is /
- ensure you can access your configured permalink from the settings table with {globals.permalink}
### Render 503 if url service did not finish
- return 503 if the url service has not finished generating the resource urls
### Rewrite sitemaps
- we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime
- we generate all urls on bootstrap
- the sitemaps service will consume created resource and router urls
- these urls will be shown on the xml pages
- we listen on url events
- we listen on router events
- we no longer have to fetch the resources, which is nice
- the urlservice pre-fetches resources and emits their urls
- the urlservice is the only component who knows which urls are valid
- i made some ES6 adaptions
- we keep the caching logic -> only regenerate xml if there is a change
- updated tests
- checked test coverage (100%)
### Re-work usage of Url utility
- replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId`
- only for resources e.g. post, author, tag
- this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime
- adapt url utility
- adapt tests
2018-06-05 19:02:20 +02:00
|
|
|
});
|