【发布时间】:2016-04-26 15:15:18
【问题描述】:
我想在 Azure 移动应用 Node.js 后端服务器中使用简单的 api。 但是经过努力却无法得到请求的内容。
谁能告诉我任何可能丢失的东西?
这是我的 api (myApi.js):
module.exports = {
"post": function (req, res, next) {
for (var k in req) {
console.log("%s: %j", k, req.k);
}
res.status(200).send('post');
}
}
这是我的 app.js:
var express = require('express'),
azureMobileApps = require('azure-mobile-apps');
var app = express();
var mobile = azureMobileApps({
// Explicitly enable the Azure Mobile Apps home page
homePage: true
});
mobile.tables.import('./tables');
mobile.api.import('./api');
mobile.tables.initialize()
.then(function () {
app.use(mobile); // Register the Azure Mobile Apps middleware
app.listen(process.env.PORT || 3000); // Listen for requests
});
这是我的控制台日志,如您所见,请求的所有内容都是未定义的。 参数:未定义 查询:未定义 标头:未定义 网址:未定义 状态码:未定义 正文:未定义 ...
【问题讨论】:
-
删除 'then' 之后的 'function' 并重试。就像这样:.then(() { app.use(mobile); app.listen(process.env.PORT || 3000); });
标签: javascript node.js azure azure-mobile-services