2017-06-25 76 views
0

我想測試一個示例模型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); 
+0

你的路徑花花公子。 – TheGinxx009

+0

@ TheGinxx009請你解釋一下。請。我是新手迴環。 – RSA

+0

你提供的網址並不是你要的網址。這條路線? – TheGinxx009

回答

0

這裏說,你應該把它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