0

我正在尝试使用 nodejs 作为 drupal 的自定义前端,并且我正在尝试想出一种方法来匹配后端菜单系统、块和视图与 express 中的路由。

示例路线

module.exports = {
'/work': function(req, res){
    //get view json for this page
    request('http://site.api/casestudies', function(err, response, body){
        views_body = JSON.parse(body);

        //get node id from alias
        request('http://site.api/alias-to-nid' + req.url, function(err, response, body){
            body = JSON.parse(body);
            var reqUrl = 'http://site.api/rest/api/' + body.path;

            request(reqUrl, function(err, response, body){
                body = JSON.parse(body);
                //get the data we need
                var node_title = body.title,
                    node_body = body.body.und[0].safe_value,
                    pageclass = 'not-front section-work';
                res.render('work', {title: node_title, class:pageclass, node_title:node_title, node_body:node_body, views_body:views_body});
            });
        });
    });
  }
}

因此,我点击 /work 并获取该页面上应该存在的 casetudies 视图的 json,然后我使用另一个请求从 /work 别名中查找节点 ID,最后在另一个嵌套请求调用中使用节点 ID 来获取页面的 json 的其余部分,然后最终将其发送到模板上。

现在 - 我有一种感觉,这是一种可怕的方式来解决这个问题。我应该怎么做!?

4

0 回答 0