diff --git a/src/declarative.js b/src/declarative.js index 13f7d11..df005a0 100644 --- a/src/declarative.js +++ b/src/declarative.js @@ -149,8 +149,8 @@ module.exports = function compileDeclarative(cb, app) { allowedIdentifiers.includes(id) || id === req || id === res || - (identifiers[i - 2] === 'req' && identifiers[i - 1] === 'params') || - (identifiers[i - 2] === 'req' && identifiers[i - 1] === 'query') || + (identifiers[i - 2] === req && identifiers[i - 1] === 'params') || + (identifiers[i - 2] === req && identifiers[i - 1] === 'query') || id === queryName || id === paramsName || queries.includes(id) || diff --git a/tests/tests/res/declarative.js b/tests/tests/res/declarative.js index d5ccda2..2b15715 100644 --- a/tests/tests/res/declarative.js +++ b/tests/tests/res/declarative.js @@ -86,6 +86,12 @@ app2.get('/test11', (req, res) => { res.send(req.query); }); +app2.get('/test12/:id', (req, res) => { + req; + let params = "1"; + res.send(params); +}); + app.listen(13333, async () => { app2.listen(13334, async () => { console.log('Server is running on port 13333'); @@ -104,6 +110,7 @@ app.listen(13333, async () => { fetch('http://localhost:13334/test9/123?name=test').then(res => res.text()), fetch('http://localhost:13334/test10/123?name=test').then(res => res.text()), fetch('http://localhost:13334/test11?name=test').then(res => res.text()), + fetch('http://localhost:13334/test12/123?name=test').then(res => res.text()), fetch('http://localhost:13334/test').then(res => res.text()), fetch('http://localhost:13334/test2?name=test&name2=test2').then(res => res.text()),