我想将自定义路由添加到使用express作为服务器的bottender 。但是当我这样做时,bottender(应该是)使用的路由返回404。这是它的样子/messenger
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;
配置.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的任何线索?
提前致谢!