此代码的环回有什么问题?
问题描述:
我想测试一个示例模型create
但它显示Cannot GET /explorer/
与浏览localhost:3001/explorer
:此代码的环回有什么问题?
var loopback = require('loopback');
var app = module.exports = loopback();
var Item = loopback.createModel(
'Item',
{
description: 'string',
completed: 'boolean'
}
);
app.model(Item);
app.use('/api', loopback.rest());
app.start = function() {
// start the web server
return app.listen(function() {
app.emit('started');
var baseUrl = app.get('url').replace(/\/$/, '');
console.log('Web server listening at: %s', baseUrl);
if (app.get('loopback-component-explorer')) {
var explorerPath = app.get('loopback-component-explorer').mountPath;
console.log('Browse your REST API at %s%s', baseUrl, explorerPath);
}
});
};
app.listen(3001);
答
这里说,你应该把它app.listen(8080)之前;所以基本上你的代码结构应该是这样的
var loopback = require('loopback');
var app = module.exports = loopback();
//you add the items here like
/*
POST /Items
GET /Items
PUT /Items
PUT /Items/{id}
HEAD /Items/{id}
GET /Items/{id}
DELETE /Items/{id}
GET /Items/{id}/exists
GET /Items/count
GET /Items/findOne
POST /Items/update
*/
var Item = loopback.createModel(
'Item',
{
description: 'string',
completed: 'boolean'
}
);
app.model(Item);
app.use('/api', loopback.rest());
app.start = function() {
// start the web server
return app.listen(function() {
app.emit('started');
var baseUrl = app.get('url').replace(/\/$/, '');
console.log('Web server listening at: %s', baseUrl);
if (app.get('loopback-component-explorer')) {
var explorerPath = app.get('loopback-component-explorer').mountPath;
console.log('Browse your REST API at %s%s', baseUrl, explorerPath);
}
});
};
app.listen(8080);
+0
我测试过,我不明白同样的结果。 – RSA
你的路径花花公子。 – TheGinxx009
@ TheGinxx009请你解释一下。请。我是新手回环。 – RSA
你提供的网址并不是你要的网址。这条路线? – TheGinxx009