Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Route annotations in routes.json and hidding routes from the client #1386

Merged
merged 2 commits into from

3 participants

@aljimenez

This pull request allows users to specify annotations in routes.json. By default routes in routes.json contain an annotation.client set to true. Setting a route's annotations.client to false prevents the route from being exposed to the client.

@aljimenez aljimenez Adding annotations specified under routes in routes.json. Setting ann…
…otations.client to true by default; if set to false then the routes are not sent to the client.
1c7e00e
@yahoocla
Owner

CLA is valid!

@aljimenez aljimenez commented on the diff
lib/app/addons/ac/deploy.server.js
@@ -69,7 +69,7 @@ YUI.add('mojito-deploy-addon', function (Y, NAME) {
initializer, // script for YUI initialization
pathToRoot,
pageData = this.adapter && this.adapter.page && this.adapter.page.data,
- pageRoutes = this.adapter && this.adapter.page && this.adapter.page.routes,
+ pageRoutes = this.adapter && this.adapter.page && this.adapter.page.clientRoutes,

We only expose client specific routes to the client.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@aljimenez aljimenez commented on the diff
lib/dispatcher.js
@@ -143,9 +143,13 @@ module.exports = {
// - routes are not contextualized anymore
if (!CACHE.routes) {
CACHE.routes = app.getRouteMap();
+ CACHE.clientRoutes = app.getRouteMap({
+ client: true
+ });

Here we filter routes by those that have the client annotation set to true (which is the default).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@aljimenez aljimenez commented on the diff
lib/router.js
@@ -162,6 +162,9 @@ module.exports = {
function registerRoutes(routes) {
Object.keys(routes).forEach(function (name) {
var route = routes[name];
+ route.annotations = route.annotations || {};
+ route.annotations.client = route.annotations.client !== false;
+ app.annotate(route.path, route.annotations);

Here we set a default annotations.client to true and use app.annotate to pass any all annotations, including any specified by the user in routes.json.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@aljimenez aljimenez changed the title from Client Routes to Route annotations in routes.json and hidding routes from the client
@aljimenez

I will merge this pull request soon, if there aren't any concerns.

@aljimenez aljimenez merged commit 471631f into from
@caridy caridy commented on the diff
lib/router.js
@@ -162,6 +162,9 @@ module.exports = {
function registerRoutes(routes) {
Object.keys(routes).forEach(function (name) {
var route = routes[name];
+ route.annotations = route.annotations || {};
+ route.annotations.client = route.annotations.client !== false;
@caridy Owner
caridy added a note

this line in confusing. is this a typecast to boolean with default to true?

It is a bit confusing, I'll add a comment. It just means that the client value is always considered true unless its set to specifically false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@caridy
Owner

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 2, 2014
  1. @aljimenez

    Adding annotations specified under routes in routes.json. Setting ann…

    aljimenez authored
    …otations.client to true by default; if set to false then the routes are not sent to the client.
  2. @aljimenez

    Updated tests.

    aljimenez authored
This page is out of date. Refresh to see the latest.
View
2  lib/app/addons/ac/deploy.server.js
@@ -69,7 +69,7 @@ YUI.add('mojito-deploy-addon', function (Y, NAME) {
initializer, // script for YUI initialization
pathToRoot,
pageData = this.adapter && this.adapter.page && this.adapter.page.data,
- pageRoutes = this.adapter && this.adapter.page && this.adapter.page.routes,
+ pageRoutes = this.adapter && this.adapter.page && this.adapter.page.clientRoutes,

We only expose client specific routes to the client.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
updateLoaderCount = store._updateLoaderCount,
loaderRess,
lang = this.ac.context.lang;
View
8 lib/dispatcher.js
@@ -107,7 +107,7 @@ module.exports = {
The `command` should be attached to the request.
@protected
- @method handleRequest
+ @method handleRequest
@param {http.ServerRequest} req
@param {Object} req.command the mojito command to be executed
@param {http.ServerResponse} res
@@ -135,7 +135,7 @@ module.exports = {
outputHandler.setLogger({ log: Y.log });
- // storing the static app config as well as contextualized
+ // storing the static app config as well as contextualized
// app config per request
outputHandler.page.staticAppConfig = appConfig;
outputHandler.page.appConfig = store.getAppConfig(context);
@@ -143,9 +143,13 @@ module.exports = {
// - routes are not contextualized anymore
if (!CACHE.routes) {
CACHE.routes = app.getRouteMap();
+ CACHE.clientRoutes = app.getRouteMap({
+ client: true
+ });

Here we filter routes by those that have the client annotation set to true (which is the default).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
}
outputHandler.page.routes = CACHE.routes;
+ outputHandler.page.clientRoutes = CACHE.clientRoutes;
// HookSystem::StartBlock
// enabling perf group
View
7 lib/router.js
@@ -18,7 +18,7 @@ Example usage:
app = express();
- app.use(mojito.middleware());
+ app.use(mojito.middleware());
...
// or specify app specific paths (preferred)
app.mojito.attachRoutes(libpath.join(__dirname, 'config', 'routes.json'));
@@ -70,7 +70,7 @@ function readConfigYCB(fullPath) {
/**
Normalizes the `routes.json` configuration.
-@param {String} name
+@param {String} name
@param {Object} route the route object from `routes.json`
@return {Object} normalized route object
**/
@@ -162,6 +162,9 @@ module.exports = {
function registerRoutes(routes) {
Object.keys(routes).forEach(function (name) {
var route = routes[name];
+ route.annotations = route.annotations || {};
+ route.annotations.client = route.annotations.client !== false;
@caridy Owner
caridy added a note

this line in confusing. is this a typecast to boolean with default to true?

It is a bit confusing, I'll add a comment. It just means that the client value is always considered true unless its set to specifically false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ app.annotate(route.path, route.annotations);

Here we set a default annotations.client to true and use app.annotate to pass any all annotations, including any specified by the user in routes.json.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Object.keys(route.verbs).forEach(function (verb) {
debug('[%s %s] installing handler', route.call, route.path);
verb = verb.toLowerCase();
View
2  tests/unit/lib/app/addons/ac/test-deploy.server.js
@@ -20,7 +20,7 @@ YUI().use('mojito-deploy-addon', 'test', 'json-parse', function(Y) {
setUp: function() {
addon = new Y.mojito.addons.ac.deploy(
{instance: {}}, // command
- {page: { routes: { 'get': { } } } } // adapter
+ {page: { clientRoutes: { 'get': { } } } } // adapter
);
addon.ac = {
http: {
View
3  tests/unit/lib/test-router.js
@@ -69,7 +69,8 @@ YUI().use('test', function (Y) {
// mock expect 'routes01.json'
root: ''
}
- }
+ },
+ annotate: function () {}
};
router._app = app;
},
Something went wrong with that request. Please try again.