I'm using Node with Express as an API. Currently this is the output if there is an unexpected error thrown:
"stack": "APIError: test error\n at new ExtendableError
(/home/user/workspace/test-api/server/helpers/error.ts:25:11)\n at new APIError
(/home/user/workspace/test-api/server/helpers/error.ts:41:5)\n
at app.use (/home/user/workspace/test-api/config/express.ts:112:24)\n
at Layer.handle_error (/home/user/workspace/test-api/node_modules/express/lib/router/layer.js:71:5)\n
at trim_prefix (/home/user/workspace/test-api/node_modules/express/lib/router/index.js:315:13)\n at /home/user/workspace/test-api/node_modules/express/lib/router/index.js:284:7\n
at Function.process_params (/home/user/workspace/test-api/node_modules/express/lib/router/index.js:335:12)\n
at next (/home/user/workspace/test-api/node_modules/express/lib/router/index.js:275:10)\n
at Layer.handle_error (/home/user/workspace/test-api/node_modules/express/lib/router/layer.js:67:12)\n
at trim_prefix (/home/user/workspace/test-api/node_modules/express/lib/router/index.js:315:13)\n
at /home/user/workspace/test-api/node_modules/express/lib/router/index.js:284:7\n
at Function.process_params (/home/user/workspace/test-api/node_modules/express/lib/router/index.js:335:12)\n
at next (/home/user/workspace/test-api/node_modules/express/lib/router/index.js:275:10)\n
at Layer.handle_error (/home/user/workspace/test-api/node_modules/express/lib/router/layer.js:67:12)\n
at trim_prefix (/home/user/workspace/test-api/node_modules/express/lib/router/index.js:315:13)\n
at /home/user/workspace/test-api/node_modules/express/lib/router/index.js:284:7\n
at Function.process_params (/home/user/workspace/test-api/node_modules/express/lib/router/index.js:335:12)\n
at next (/home/user/workspace/test-api/node_modules/express/lib/router/index.js:275:10)\n
at /home/user/workspace/test-api/node_modules/express/lib/router/index.js:635:15\n
at Immediate.next (/home/user/workspace/test-api/node_modules/express/lib/router/index.js:260:14)\n
at Immediate.<anonymous> (/home/user/workspace/test-api/node_modules/express/lib/router/index.js:635:15)\n
at runCallback (timers.js:812:20)\n
at tryOnImmediate (timers.js:768:5)\n
at processImmediate [as _immediateCallback] (timers.js:745:5)",
I would love it if I can display the file, linenumber and function where this happened but I have no clue how to do this.
Can anyone help or point me in the right direction?
For reference, you can see the boilerplate my project is based on here. Express setup can be found in config/express.ts
Try adding source-map-support. Your stack trace is actually showing you the file and line number of the code that triggered an error but it seems to show it on transpiled code. Install the package and call install() inside your entry file:
$ npm install --save-dev source-map-support
// entry.ts
require('source-map-support').install();
Related
I now get this error in my NodeJS server's logs:
[2021-11-13T14:43:45.107Z] URIError: Failed to decode param '/cgi-bin/%%32%65%%32%65/bin/sh'
at decodeURIComponent (<anonymous>)
at decode_param (~/node_modules/express/lib/router/layer.js:172:12)
at Layer.match (~/node_modules/express/lib/router/layer.js:123:27)
at matchLayer (~/node_modules/express/lib/router/index.js:574:18)
at next (~/node_modules/express/lib/router/index.js:220:15)
at expressInit (~/node_modules/express/lib/middleware/init.js:40:5)
at Layer.handle [as handle_request] (~/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (~/node_modules/express/lib/router/index.js:317:13)
at ~/node_modules/express/lib/router/index.js:284:7
at Function.process_params (~/node_modules/express/lib/router/index.js:335:12)
at next (~/node_modules/express/lib/router/index.js:275:10)
at query (~/node_modules/express/lib/middleware/query.js:45:5)
at Layer.handle [as handle_request] (~/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (~/node_modules/express/lib/router/index.js:317:13)
at ~/node_modules/express/lib/router/index.js:284:7
at Function.process_params (~/node_modules/express/lib/router/index.js:335:12)
It seems related to Apache's path traversal vulnerability. My server does not run Apache but I would still like to blacklist the IP address. This request does not print to the logs, and does not call my app's code in app.js.
How can I log the IP of the request?
I have setup hyperledger fabric and also started network.But when I
create composer-rest-server and access it on my browser and access
https://localhost:3000/explorer
I'm getting an error:
Unhandled error for request GET /explorer: Error: Cannot GET /explorer
at raiseUrlNotFoundError (/usr/local/lib/node_modules/composer-rest-
server/node_modules/loopback/server/middleware/url-not-found.js:21:17)
at Layer.handle [as handle_request]
(/usr/local/lib/node_modules/composer-rest-
server/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/usr/local/lib/node_modules/composer-rest-
server/node_modules/express/lib/router/index.js:317:13)
at /usr/local/lib/node_modules/composer-rest-
server/node_modules/express/lib/router/index.js:284:7
at Function.process_params (/usr/local/lib/node_modules/composer-rest-
server/node_modules/express/lib/router/index.js:335:12)
at next (/usr/local/lib/node_modules/composer-rest-
server/node_modules/express/lib/router/index.js:275:10)
at /usr/local/lib/node_modules/composer-rest-
server/node_modules/express/lib/router/index.js:635:15
at next (/usr/local/lib/node_modules/composer-rest-
server/node_modules/express/lib/router/index.js:260:14)
at Function.handle (/usr/local/lib/node_modules/composer-rest-
server/node_modules/express/lib/router/index.js:174:3)
at router (/usr/local/lib/node_modules/composer-rest-
server/node_modules/express/lib/router/index.js:47:12)
at Layer.handle [as handle_request]
(/usr/local/lib/node_modules/composer-rest-
server/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/usr/local/lib/node_modules/composer-rest-
server/node_modules/express/lib/router/index.js:317:13)
at /usr/local/lib/node_modules/composer-rest-
server/node_modules/express/lib/router/index.js:284:7
at Function.process_params (/usr/local/lib/node_modules/composer-rest-
server/node_modules/express/lib/router/index.js:335:12)
at next (/usr/local/lib/node_modules/composer-rest-
server/node_modules/express/lib/router/index.js:275:10)
at urlencodedParser (/usr/local/lib/node_modules/composer-rest-
server/node_modules/body-parser/lib/types/urlencoded.js:91:7)
After you start the server it asks certain question with you, one of them is
Specify if you want to enable the explorer test interface
Make sure you put yes in it
Greenie here. Trying to start with a new Express project and I already hit a snag. I used the generator to start my app (express --view=handlebars sms_alarm_nodejs) and I got this error:
Error: Failed to lookup view "error" in views directory "c:\Users\joe_t\workspace\sms_alarm_nodejs\views"
application.js:630
at Function.render (c:\Users\joe_t\workspace\sms_alarm_nodejs\node_modules\express\lib\application.js:580:17)
at ServerResponse.render (c:\Users\joe_t\workspace\sms_alarm_nodejs\node_modules\express\lib\response.js:971:7)
at c:\Users\joe_t\workspace\sms_alarm_nodejs\app.js:43:7
at Layer.handle_error (c:\Users\joe_t\workspace\sms_alarm_nodejs\node_modules\express\lib\router\layer.js:71:5)
at trim_prefix (c:\Users\joe_t\workspace\sms_alarm_nodejs\node_modules\express\lib\router\index.js:315:13)
at c:\Users\joe_t\workspace\sms_alarm_nodejs\node_modules\express\lib\router\index.js:284:7
at Function.process_params (c:\Users\joe_t\workspace\sms_alarm_nodejs\node_modules\express\lib\router\index.js:335:12)
at next (c:\Users\joe_t\workspace\sms_alarm_nodejs\node_modules\express\lib\router\index.js:275:10)
at Layer.handle_error (c:\Users\joe_t\workspace\sms_alarm_nodejs\node_modules\express\lib\router\layer.js:67:12)
at trim_prefix (c:\Users\joe_t\workspace\sms_alarm_nodejs\node_modules\express\lib\router\index.js:315:13)
Am I missing a view reference in app.js? I assumed the app generator would handle this for me to start. And can I use handlebars? The sample I saw used pug.
Fixed it. I had to use --view=hbs as the generator parameter.
Using MEAN.JS is possible to bring a Server Error changing this:
http://localhost:3000/#!/
To:
http://localhost:3000/%C0#!/
Error: Bad Request
at SendStream.error (/home/username/Project/node_modules/express/node_modules/send/index.js:239:16)
at SendStream.pipe (/home/username/Project/node_modules/express/node_modules/send/index.js:411:32)
at serveStatic (/home/username/Project/node_modules/express/node_modules/serve-static/index.js:110:12)
at Layer.handle [as handle_request] (/home/username/Project/node_modules/express/lib/router/layer.js:82:5)
at trim_prefix (/home/username/Project/node_modules/express/lib/router/index.js:269:13)
at /home/username/Project/node_modules/express/lib/router/index.js:236:9
at Function.proto.process_params (/home/username/Project/node_modules/express/lib/router/index.js:311:12)
at /home/username/Project/node_modules/express/lib/router/index.js:227:12
at Function.match_layer (/home/ec2-user/Project/node_modules/express/lib/router/index.js:294:3)
at next (/home/username/Project/node_modules/express/lib/router/index.js:188:10)
We can see the username of the server and this is dangerous...
Any suggestion to solve this bug?
The solution is easy. Only need to modify the message of file app/views/500.server.view.html
when i trying to create template and node execute that gives this error please help me
Error: Failed to lookup view "default" in views directory "C:\Users\Act027\Desktop\node\views"
at EventEmitter.app.render (C:\Users\Act027\Desktop\node\node_modules\express\lib\application.js:519:17)
at ServerResponse.res.render (C:\Users\Act027\Desktop\node\node_modules\express\lib\response.js:904:7)
at C:\Users\Act027\Desktop\node\app.js:7:6
at Layer.handle [as handle_request] (C:\Users\Act027\Desktop\node\node_modules\express\lib\router\layer.js:82:5)
at next (C:\Users\Act027\Desktop\node\node_modules\express\lib\router\route.js:100:13)
at Route.dispatch (C:\Users\Act027\Desktop\node\node_modules\express\lib\router\route.js:81:3)
at Layer.handle [as handle_request] (C:\Users\Act027\Desktop\node\node_modules\express\lib\router\layer.js:82:5)
at C:\Users\Act027\Desktop\node\node_modules\express\lib\router\index.js:235:24
at Function.proto.process_params (C:\Users\Act027\Desktop\node\node_modules\express\lib\router\index.js:313:12)
at C:\Users\Act027\Desktop\node\node_modules\express\lib\router\index.js:229:12
You are either in the wrong folder or you have no view named "default".