javascript - NodeJS is throwing an error on a route starting with a percent sign -
i have server written nodejs, backend setup this
app.use(express.static(__dirname)) app.get('/', function(req, res){ res.send('main page here') }); app.get('/*', function(req, res){ res.send('404 dude') }); app.use(function(err, req, res, next){ console.error(err.stack); });
when nail server @ /%
, stack trace:
error: bad request @ sendstream.error (/users/danielchao/code/node/node_modules/express/node_modules/send/index.js:239:16) @ sendstream.pipe (/users/danielchao/code/node/node_modules/express/node_modules/send/index.js:411:32) @ servestatic (/users/danielchao/code/node/node_modules/express/node_modules/serve-static/index.js:107:12) @ layer.handle [as handle_request] (/users/danielchao/code/node/node_modules/express/lib/router/layer.js:82:5) @ trim_prefix (/users/danielchao/code/node/node_modules/express/lib/router/index.js:270:13) @ /users/danielchao/code/node/node_modules/express/lib/router/index.js:237:9 @ function.proto.process_params (/users/danielchao/code/node/node_modules/express/lib/router/index.js:312:12) @ /users/danielchao/code/node/node_modules/express/lib/router/index.js:228:12 @ function.match_layer (/users/danielchao/code/node/node_modules/express/lib/router/index.js:295:3) @ next (/users/danielchao/code/node/node_modules/express/lib/router/index.js:189:10)
why static assets handler erroring out on this? ideally should handled 404.
%
escape character in url.
if want literal %
in url utilize this: %25
javascript node.js express
No comments:
Post a Comment