alexa / alexa-skills-kit-sdk-for-nodejs

The Alexa Skills Kit SDK for Node.js helps you get a skill up and running quickly, letting you focus on skill logic instead of boilerplate code.
Apache License 2.0
3.12k stars 736 forks source link

Why am I getting: Error in processing request. Do not register any parsers before using the adapter #698

Open garciaraul85 opened 2 years ago

garciaraul85 commented 2 years ago

I am creating a skill using nodejs + express + express adapter. I want to add a middleware to intercept the request and check the request body to do some verifications but I get this error: Error in processing request. Do not register any parsers before using the adapter

This is my code for the index.ts:

const app: express.Application = express()

// Skill entry point
const skill = application.getSkillBuilder.createSkillForWebService()

const adapter = new ExpressAdapter(skill, config.verifySignature, config.verifyTimestamp)
app.use(bodyParser.json())

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
app.use((req: any, res: any, next: () => void) => {
    console.log(req)
})
app.post("/", adapter.getRequestHandlers())

const listener = app.listen(PORT, function () {
    const { address, port } = listener.address() as AddressInfo
    logger.debug("%s listening to %s%s", app.name, address, port)
})

So I get the body printed, but I get the error: Error in processing request. Do not register any parsers before using the adapter

But if I remove the line: app.use(bodyParser.json()) The skill works, but the body.req prints undefined in:

app.use((req: any, res: any, next: () => void) => {
    console.log(req)
})

Any tip on how to handle this?

rahulawl commented 2 years ago

Is this issue/feature-request still relevant? We are working on prioritization of relevant issues and cleanup of rest. If we don’t hear back in 2 weeks, we will assume that the issue is not relevant and we will close it.