生产模式下的CompoundJS呈现网页,而不是检索JSON数据

我是CompoundJS的新手,我不太确定这是否是正确的行为。

我使用以下代码在PROD模式下启动服务器:

NODE_ENV=production compound server 8081

然后我打:

http://localhost:8081/categories/

我是除了看到从服务器检索到一些JSON

相反,它会呈现如下所示的页面:

在这里输入图像描述

正如@Pablo在评论中提到的那样,只需在调用控制器的时候使用.json即可。

如下所示:

 GET http://localhost:3000/categories.json 

预计您的控制器将处理两者,就像在生成的控制器中一样。

一个具体的例子: [approot]/app/controllers/category_controller.js

在JavaScript中:

 action(function index() { this.title = 'Categories index'; Category.all(function (err, categories) { respondTo(function (format) { // Use format.json and the send method to return JSON data when // .json is specified at the end of the controller format.json(function () { send({code: 200, data: categories}); }); format.html(function () { render({ categories: categories }); }); }); }); }); 

在CoffeeScript中:

 action index = -> @title = "Categories index" Category.all (err, categories) -> respondTo (format) -> # Use format.json and the send method to return JSON data when # .json is specified at the end of the controller format.json -> send code: 200 data: categories format.html -> render categories: categories