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

Middleware does not work for root path #128

Open
jkinghed opened this issue Oct 7, 2019 · 0 comments · May be fixed by #227
Open

Middleware does not work for root path #128

jkinghed opened this issue Oct 7, 2019 · 0 comments · May be fixed by #227
Assignees
Milestone

Comments

@jkinghed
Copy link

jkinghed commented Oct 7, 2019

Either I'm missing something in the documentation (very likely), or middleware does not trigger for root paths. I've tried both GET and POST.

Example code

const lambdaApi = require('lambda-api');
const api = lambdaApi({
    base: 'user',
    logger: true
});

api.use((req, res, next) => {
    console.log('MIDDLEWARE START');
    req.myVar = 'YES, HELLO';

    next();
});

//static path
api.get('/hello', async (req, res) => {

    console.log('/hello', req.myVar);
    res.json({hello: req.myVar});

});

//root path
api.get('/', async (req, res) => {

    console.log('root', req.myVar);

    res.json({hello: req.myVar});

});

exports.handler = async (event, context) => {
    console.log('event:', JSON.stringify(event, undefined, 4));
    console.log('context:', JSON.stringify(context, undefined, 4));
    return await api.run(event, context);
};

And logs

image

API Gateway has ANY method for base path /user

Any pointers on what I'm doing wrong?

@naorpeled naorpeled self-assigned this Feb 3, 2023
@naorpeled naorpeled added this to the v1.2.0 milestone Dec 31, 2024
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

Successfully merging a pull request may close this issue.

2 participants