我想将自定义路由添加到使用bottender作为服务器的express。但是当我这样做时,bottender使用的路径(应该是/messenger
)返回404.这就是它的样子
index.js
require('dotenv').config();
const { MessengerBot } = require('bottender');
const express = require('express');
const bodyParser = require('body-parser');
const { registerRoutes } = require('bottender/express');
const helmet = require('helmet');
const cors = require('cors');
const compression = require('compression');
const handler = require('./handlers');
const { messenger } = require('./config');
const logger = require('./utils/logger');
const errorController = require('./controllers/errorController');
const ticketsController = require('./controllers/ticketsController');
const { APP_PORT, NODE_ENV } = process.env;
const server = express();
/* istanbul ignore next */
const verify = (req, res, buf) => {
req.rawBody = buf.toString();
};
server.use('/images', express.static('images'));
server.use('/facebook-payment', express.static('payment-page/build'));
server.use(compression());
server.use(helmet());
server.use(cors());
server.use(bodyParser.json({ verify }));
server.use(require('morgan')('short', { stream: logger.logStream }));
const router = express.Router();
/* Custom APIs */
server.use('/api', router);
server.use('/api/tickets', ticketsController.getByEventId);
/* Error Handling */
server.use(errorController.error404);
server.use(errorController.generalError);
const bots = {
messenger: new MessengerBot(messenger.bot).onEvent(handler.messenger.execute),
// Define other platform bots here!
};
registerRoutes(server, bots.messenger, messenger.server);
// Start server
server.listen(APP_PORT, () => logger.info(`ENV[${NODE_ENV}] - server is listening on port ${APP_PORT}...`));
module.exports = server;
config.js
module.exports = {
messenger: {
profile,
bot: {
accessToken: FB_ACCESS_TOKEN,
appId: APP_ID,
appSecret: APP_SECRET,
mapPageToAccessToken: bots.getTokenByPageById,
},
server: {
verifyToken: FB_VERIFY_TOKEN,
path: '/messenger',
},
},
};
为什么bottender使用的路由返回404的任何线索?
提前致谢!
答案 0 :(得分:2)
虽然我不确定LDFLAGS
的实施情况,但您可能需要尝试将errorController
放在他们面前。
如:
registerRoutes()
答案 1 :(得分:1)
我可以在注册自定义API之前使用Sub Macro1()
Dim j As Long
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
ws.Activate
For j = 10 To 1 Step -1
If ws.Cells(j, 3) = "" Then
ws.Rows(j).Delete
End If
Next j
Next
End Sub
第一个来解决此问题。所以代码看起来像这样
registerRoutes