环回:应用未定义



我在服务器/中间件/机器人中有一个自定义脚本.js内容如下:

module.exports = function(app) {
app.get('/robots.txt', function (req, res) {
res.type('text/plain');
if (app.settings.env === 'production') {
res.send("User-agent: *nAllow: /");
} else {
res.send("User-agent: *nDisallow: /");
}
});
};

但是,我收到错误消息,指出应用程序未定义。

我尝试在服务器底部添加以下行.js:

module.exports = app;

但没有运气。

当我删除模块导出行并要求应用程序从../服务器我收到以下错误:

[2018-07-07T09:51:30.077Z] error: uncaughtException: Middleware factory must be a function

如何在服务器外部访问应用程序.js?我密切关注文档,但我无法做到这一点。

尝试将服务器.js导入到您的机器人.js文件中

const app = require('../server.js')

并在服务器中导出您的应用程序.js

`   const loopback = require('loopback');` 
const app = module.exports = loopback();

您是否已经尝试导入服务器?

const app = require('../server')
module.exports = function() {
app.get('/robots.txt', function (req, res) {
res.type('text/plain');
if (app.settings.env === 'production') {
res.send("User-agent: *nAllow: /");
} else {
res.send("User-agent: *nDisallow: /");
}
});
};

最新更新