Skip to content

How to get the context after migration? #903

Description

@twkevinzhang

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions