Skip to content
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.

Commit

Permalink
Merge pull request #1386 from yahoo/client-routes
Browse files Browse the repository at this point in the history
Route annotations in routes.json and hidding routes from the client
  • Loading branch information
aljimenez committed Jul 14, 2014
2 parents 8838fc3 + 32b34f2 commit 471631f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/app/addons/ac/deploy.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
updateLoaderCount = store._updateLoaderCount,
loaderRess,
lang = this.ac.context.lang;
Expand Down
8 changes: 6 additions & 2 deletions lib/dispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -135,17 +135,21 @@ 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);

// - routes are not contextualized anymore
if (!CACHE.routes) {
CACHE.routes = app.getRouteMap();
CACHE.clientRoutes = app.getRouteMap({
client: true
});
}

outputHandler.page.routes = CACHE.routes;
outputHandler.page.clientRoutes = CACHE.clientRoutes;

// HookSystem::StartBlock
// enabling perf group
Expand Down
7 changes: 5 additions & 2 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down Expand Up @@ -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
**/
Expand Down Expand Up @@ -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);
Object.keys(route.verbs).forEach(function (verb) {
debug('[%s %s] installing handler', route.call, route.path);
verb = verb.toLowerCase();
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/lib/app/addons/ac/test-deploy.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/lib/test-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ YUI().use('test', function (Y) {
// mock expect 'routes01.json'
root: ''
}
}
},
annotate: function () {}
};
router._app = app;
},
Expand Down

0 comments on commit 471631f

Please sign in to comment.