MVC в узле и в целом: как модели связаны с представлениями?

Я начинаю с node.js и создаю простую инфраструктуру MVC. Пока у меня работает фронт-контроллер (или «диспетчер», если хотите). Маршрутизация происходит через конфигурационный модуль диспетчера, как показано на рисунке.

Мои вопросы в конце, сразу после кода. Кроме того, это упражнение в обучении ноде, пожалуйста, не предлагайте express.js и лайки.

dispatcherConfig.js:

var url = require('url');

(function() {
    var dispatcherConfig = {
        '/'                 : 'homeController',
        '/index.html'       : 'homeController',
        '/sayHello.html'    : 'helloController',
        '404'               : '404Controller'
    };

    module.exports.getController = function(request) {
        var route = url.parse(request.url, true).pathname;
        if(dispatcherConfig[route]) {
            return dispatcherConfig[route];
        }
        return dispatcherConfig['404'];
    }
}());


Это используетсяdispatcher.js:

var dispatcherConfig = require('./config/dispatcherConfig');

(function() {
    module.exports.dispatch = function(request, response) {
        var requiredController = dispatcherConfig.getController(request);
        var controller = require('./controllers/' + requiredController);
        controller.doService(request, response);
    }
}());


А вот как выглядит пример контроллера (тоже работает денди) -homeController.js:
(Пожалуйста, пока игнорируйте встроенный код представления)

(function() {
    var homeController = {
        doService: function(request, response) {
            response.write('<form action="/sayHello.html" method="GET">' + 
                '<input id="name" name="name" size="20" />' + 
                '<input type="submit" value="Submit" />' + 
                '</form>');
        }
    }

    module.exports.doService = function(request, response) {
        return homeController.doService(request, response);
    }
}());


Эта маршрутизация работает хорошо. Я получил контроллеры, легко подключающиеся к шаблонам URL, и эмулирую также тип контроллера мультиакции пружины, дополнительно проверяя объект запроса.

Здесь необходимо сделать три очевидные вещи:

Creating view objects Creating model objects Binding views and models

Questions:

In MVC (spring at least), it's controllers that bind a view with a model. Is this the best way of doing it? What if I maintain separate a separate configuration which describes what view binds to what model, and the controller only routes to a view. Is this wrong and not MVC?

What is a good way to represent a view in node.js? Since it is heavily template based, what templating options are on offer (matured ones)?

If I load a file to be served statically (say CSS file, loaded through file read into memory), and I keep a reference to the contents in the global/app scope, then subsequent requests can be served directly from memory, resulting in phenomenal speeds, is this assumption correct? In fact, we can guarantee that after the first request entering the node server (which will trigger the file read and the contents being loaded into mem), all subsequent requests will be served from memory (for such static content).

What is the low level (framework-less) way of grabbing POST data in raw node.js?

Благодарю.

Ответы на вопрос(2)

Ваш ответ на вопрос