gpt4 book ai didi

mysql - 环回应用程序函数错误

转载 作者:行者123 更新时间:2023-11-29 09:37:36 24 4
gpt4 key购买 nike

我正在使用loopback和mysql开发vuejs应用程序。当我运行应用程序时,我遇到的错误是app.start 不是函数

这是我的代码 server.js ..

// Copyright IBM Corp. 2016. All Rights Reserved.
// Node module: loopback-workspace
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

'use strict';

var loopback = require('loopback');
var boot = require('loopback-boot');

var app = module.exports = loopback();

module.exports = function(app) {
// Install a "/ping" route that returns "pong"
app.get('/ping', function(req, res) {
res.send('pong');
});
};

// 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();
});

这是我的route.js文件代码

'use strict';
module.exports = function(app) {
var router = app.loopback.Router();
router.get('/ping', function(req, res) {
res.send('pongaroo');
});
app.use(router);
};

最佳答案

所有 server.js 文件都应包含一个名为 app.start 的函数。在此函数中,只有服务器启动。在 server.js 文件中尝试添加 app.start(),希望能解决您的问题。请参阅下面的 app.start 函数的简单代码。

    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);
}
});
};

关于mysql - 环回应用程序函数错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57261479/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com