1
超級菜鳥的特性「createModel」在這裏,我必須用迴環這裏REST API的一個問題是我的錯誤:Node.js的環回:類型錯誤:無法讀取未定義
TypeError: Cannot read property 'createModel' of undefined
at module.exports (/home/...../node_modules/loopback-component-oauth2/lib/models/oauth2-models.js:35:30)
at module.exports (/home/...../node_modules/loopback-component-oauth2/lib/models/index.js:24:42)
at Function.module.exports [as oAuth2Provider] (/home/...../node_modules/loopback-component-oauth2/lib/oauth2-loopback.js:48:16)
at Object.<anonymous> (/home/...../server/server.js:17:8)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Function.Module.runMain (module.js:605:10)
at startup (bootstrap_node.js:158:16)
at bootstrap_node.js:575:3
這裏是我在我server.js:
'use strict';
var loopback = require('loopback');
var boot = require('loopback-boot');
// pour OATH2
var oauth2 = require('loopback-component-oauth2');
var app = module.exports = loopback();
// OATH2
var options = {
dataSource: app.dataSources.db, // Data source for oAuth2 metadata persistence
loginPage: '/login', // The login page URL
loginPath: '/login' // The login form processing URL
};
oauth2.oAuth2Provider(
app, // The app instance
options // The options
);
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);
}
});
};
// Bootstrap the application, configure models, datasources and middleware.
// Sub-apps like REST API are mounted via boot scripts.
boot(app, __dirname, function(err) {
if (err) throw err;
// start the server if `$ node server.js`
if (require.main === module)
app.start();
});
我已經簽了一大堆類似的話題,一直無法找出任何解決我的問題。 我注意到當我做一個控制檯日誌時,我的數據庫是「{}」,如果我把所有的OATH2放在應用程序啓動函數中,它會發出不同的錯誤,但看起來它不是要走的路。
非常感謝您的幫助(並請原諒我,如果這還不夠清楚:))