Yoctol/bottender

How to get the context after migration?

twkevinzhang opened this issue · 0 comments

i want to run the line-notify and line-bot routing services at the same time and same port, like this:

const bodyParser = require('body-parser');
const express = require('express');
const { bottender } = require('bottender');
// const { createServer } = require('bottender/express');

const app = bottender({
  dev: process.env.NODE_ENV !== 'production',
});

const handle = app.getRequestHandler();
app.prepare().then(() => {
	const server = express();
	const verify = (req, _, buf) => {
		req.rawBody = buf.toString();
	};
	server.use(bodyParser.json({ verify }));
	server.use(bodyParser.urlencoded({ extended: false, verify }));

	server.use('/notify', require('./routes/line-notify'));
	// some bot route in here...

	server.get('/hello', (req, res) => {
		res.json({ hello: "world" });
	});

	server.all('*', (req, res) => {
		return handle(req, res);
	});

	const port = Number(process.env.PORT) || 5001;
	server.listen(port, err => {
		if (err) throw err;
		console.log(`> Ready on http://localhost:${port}`);
	});
});

so I followed the following article for migration:
https://bottender.js.org/docs/zh-TW/advanced-guides-custom-server

but my project cannot execute src/index.js when let bottender start to node server.js in package.json, so i can't get context!

i also refer to other articles:
https://blog.techbridge.cc/2018/05/10/lets-build-weather-bot-1/

but when I require('Bottender/express'), i get Error: Cannot find module'Bottender/express'. is it deprecated?

how can i do? how to get the context after migration?
Thanks a lot for any ideas.