Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get the context after migration? #903

Open
twkevinzhang opened this issue Jun 2, 2021 · 0 comments
Open

How to get the context after migration? #903

twkevinzhang opened this issue Jun 2, 2021 · 0 comments

Comments

@twkevinzhang
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant