Tuesday, 3 February 2015

keystone more deeper 2

The mount.js is a very important file to setup a lot of things for keystone, e.g. mongoose. session. and routes. node_models/keystone/lib/core/mount.js

Mongoose setting up is the last code block in this file. You can find connections are created here. However, as I mentioned in previous posts, keystone handles connection error in a wrong way. They should not throw an error, it will stop nodejs server. The thing is developer haven't got a chance to deal with it. all the code run in keystone.start() function, even we can catch the error, keystone's thread already terminated .

Session:

The code for session management is designed for loading session from mongoose and reconstruct user information in request.


Routes:

All routes are managed here:

In mount.js:

if (!this.get('headless')) {
this.routes(app);
}

// Configure application routes
if ('function' === typeof this.get('routes')) {
this.get('routes')(app);
}


In the first "if statement", this.routes() is route.js

in routes.js:

// Generic Lists API
app.all('/keystone/:list/:page([0-9]{1,5})?', initList(true), require('../../routes/views/list'));

This line of code route all keystone object list view requests to 'roues/views/list'.

In the second "if statement",  you can find "routes" in the keystone.js of your project:

keystone.set('routes', require('./routes'));

You can find this:

exports = module.exports = function(app) {
// Views
app.get('/', routes.views.index);
app.get('/gallery', routes.views.gallery);
app.all('/contact', routes.views.contact);

This is the routes of your project (before login admin-ui, if you have blog, the link of blog will be here).






























































No comments:

Post a comment