Skip to content

Instantly share code, notes, and snippets.

@grawk
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grawk/2f237bfbdd2378aa6934 to your computer and use it in GitHub Desktop.
Save grawk/2f237bfbdd2378aa6934 to your computer and use it in GitHub Desktop.
discussion of kraken-examples routes

is this what you think routes/index.js should look like:

'use strict';

var IndexModel = require('../models/index');
var setLocale = require('./setLocale');

module.exports = function (router) {
    router.get('/', indexRoute);
    setLocale(router);
};

function indexRoute(req, res) {
    var model = new IndexModel();
    res.render('index', model);
};

with routes/setLocale.js:

'use strict';

module.exports = function (router) {
    router.get('/setLocale/:locale', setLocale);
};

function setLocale(req, res) {
    res.cookie('locale', req.params.locale);
    res.redirect('/');
};

my understanding is that any module under the routes directory should have a route signature and the main routes file needs to register all these routes as i've done in index.js above

@jasisk
Copy link

jasisk commented Aug 13, 2014

more like ...

routes/index.js

'use strict';

var IndexModel = require('../models/index');
var setLocale = require('./setLocale');

module.exports = function (router) {
    router.get('/', indexRoute);
    router.get('/setLocale/:locale', setLocale);
};

function indexRoute(req, res) {
    var model = new IndexModel();
    res.render('index', model);
};

routes/setLocale.js

'use strict';

module.exports = function setLocale(req, res) {
    res.cookie('locale', req.params.locale);
    res.redirect('/');
};

@grawk
Copy link
Author

grawk commented Aug 13, 2014

Hm. But in that case, routes/setLocale.js actually has the signature of a controller. So shouldn't it then live in controllers/setLocale.js ?

@jasisk
Copy link

jasisk commented Aug 13, 2014

That's not a controller. A controller takes a router. That's a route handler.

@grawk
Copy link
Author

grawk commented Aug 13, 2014

OK. good enough for me. let me fix all this and resubmit the PR

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