MeteorJs Error makes the site stop loading - node.js

Eror: url must be a relative URL: http://www.mafengwo.com/
at _.extend.classify (packages/routepolicy/routepolicy.js:103)
at Object.Inject.appUrl (packages/meteorhacks:inject-initial/lib/inject-core.js:43)
at Object.Package [as handle] (packages/gadicohen:headers/headers-server.js:192)
at next (/home/timekeeper/bundle/programs/server/npm/webapp/node_modules/connect/lib/proto.js:190:15)
at next (/home/timekeeper/bundle/programs/server/npm/webapp/node_modules/connect/lib/proto.js:165:78)
at Function.app.handle (/home/timekeeper/bundle/programs/server/npm/webapp/node_modules/connect/lib/proto.js:198:3)
at Object.fn [as handle] (/home/timekeeper/bundle/programs/server/npm/webapp/node_modules/connect/lib/proto.js:74:14)
at next (/home/timekeeper/bundle/programs/server/npm/webapp/node_modules/connect/lib/proto.js:190:15)
at Object.WebAppInternals.staticFilesMiddleware (packages/webapp/webapp_server.js:400)
at packages/webapp/webapp_server.js:651
I get the above error and i have no idea what it means . I don't even know where the url comes from. But it makes my website work no more.

Related

My Express/Node.js server keeps hanging up with read ECONNRESET

Backend Setup:
Node.js/Express server running on port 5000
AWS S3 (for images)
AWS RDS Mysql (for data)
Hi guys,
I'm a frontend guy, so I don't know much about backend, I just started learning.
I have a Node.js/Express server on port 5000 that I use to connect to an S3 bucket and an RDS Mysql database, that is enough for the React frontend I'm developing at the moment.
I use nodemon to deal with disconnects and reconnect automatically. It used to work just fine 24/7, but I must have changed something during the last 3 months and now it crashes several times a day and I have to restart the server manually. It's not a huge deal but I would like to learn how to deal with it.
Here's the error I keep getting:
[nodemon] restarting due to changes...
[nodemon] starting `node server.js`
Listening on port 5000..
Connection Established Successfully
Error: read ECONNRESET
at TCP.onStreamRead (internal/stream_base_commons.js:205:27)
--------------------
at Protocol._enqueue (/Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/mysql/lib/protocol/Protocol.js:144:48)
at Connection.query (/Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/mysql/lib/Connection.js:198:25)
at /Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/routes/meProfileImageData.js:10:12
at Layer.handle [as handle_request] (/Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/express/lib/router/layer.js:95:5)
at next (/Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/express/lib/router/layer.js:95:5)
at /Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/express/lib/router/index.js:281:22
at Function.process_params (/Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/express/lib/router/index.js:335:12)
at next (/Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/express/lib/router/index.js:275:10) {
errno: 'ECONNRESET',
code: 'ECONNRESET',
syscall: 'read',
fatal: true
}
Error: Cannot enqueue Query after fatal error.
at Protocol._validateEnqueue (/Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/mysql/lib/protocol/Protocol.js:212:16)
at Protocol._enqueue (/Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/mysql/lib/protocol/Protocol.js:138:13)
at Connection.query (/Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/mysql/lib/Connection.js:198:25)
at /Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/routes/meProfileImageData.js:10:12
at Layer.handle [as handle_request] (/Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/express/lib/router/layer.js:95:5)
at next (/Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/express/lib/router/layer.js:95:5)
at /Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/express/lib/router/index.js:281:22
at Function.process_params (/Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/express/lib/router/index.js:335:12) {
code: 'PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR',
fatal: false
}
Obviously the second part happens when I try to connect without knowing the server has already crashed.
There are plenty of posts on stackoverflow about similar ECONNRESET problems, so it's very possible that my exact problem has already been replied somewhere else, but to be honest I'm just not good enough at this yet to assimilate the answer by myself, I could use some pointers as to what files the problem seems to be in or whatever you could tell me.
I have seen in several posts that the best way to deal with this kind of problem is to set error listeners, and I'm happy to do just that, but to be honest I don't know where to start because the problem happens when I'm not using the server usually, like at night or when I'm not even in front of the computer. I have no idea how to reproduce the problem on my own, it just happens by itself whenever it happens, so that's why it's so hard for me to know where to start. I looked at the logs on my S3 and RDS Mysql and didn't see anything that seemed directly connected to this.
Could you offer me some pointers based on what you see here? I have some possible ideas:
could it be the router at index.js causing this?
when I look at my RDS Mysql database panel I see at the moment there are 3 active connections, even though I stopped working like 2 hours ago. Could it be that those connections timing out are causing this? (read this in another post)
could it be meProfileImageData.js that should get error listening first?
That's all I have for now, any ideas or pointers are highly welcome, and I'll be glad to run any tests or install any necessary additional software to troubleshoot this if you feel like putting in the time to help me.
Thanks
EDIT 1: had a new error today that seems to point at connections being closed automatically and Node.js not dealing with it before there is an attempt to connect:
Error: read ETIMEDOUT
at TCP.onStreamRead (internal/stream_base_commons.js:205:27)
--------------------
at Protocol._enqueue (/Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/mysql/lib/protocol/Protocol.js:144:48)
at Connection.query (/Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/mysql/lib/Connection.js:198:25)
at /Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/routes/meProfileImageData.js:10:12
at Layer.handle [as handle_request] (/Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/express/lib/router/layer.js:95:5)
at next (/Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/express/lib/router/layer.js:95:5)
at /Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/express/lib/router/index.js:281:22
at Function.process_params (/Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/express/lib/router/index.js:335:12)
at next (/Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/express/lib/router/index.js:275:10) {
errno: 'ETIMEDOUT',
code: 'ETIMEDOUT',
syscall: 'read',
fatal: true

How can I improve express.js error stack trace?

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();

Getting error when starting a brand new generator-built app

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.

How to find the source of 'write after end'

Sometimes, my (large) application gives the following error:
Error: write after end
at ServerResponse.OutgoingMessage.write(_http_outgoing.js:413:15)
at ServerResponse.res.write(/nodeapp/node_modules/express/node_modules/connect/lib/middleware/compress.js:110:17)
at ServerResponse.res.end(/nodeapp/node_modules/express/node_modules/connect/lib/middleware/compress.js:116:14)
at ServerResponse.res.send(/nodeapp/node_modules/express/lib/response.js:153:8)
at fn(/nodeapp/node_modules/express/lib/response.js:797:10)
at/nodeapp/node_modules/vash/build/vash.js:2082:4
at Object.vash.loadFile (/nodeapp/node_modules/vash/build/vash.js:2070:10)
at View.vash.renderFile [as engine] (/nodeapp/node_modules/vash/build/vash.js:2078:8)
at View.render (/nodeapp/node_modules/express/lib/view.js:76:8)
at Function.app.render (/nodeapp/node_modules/express/lib/application.js:504:10)
Is there a way to find out in which line this error happend? Normally the file is mentioned in the stack trace, but not in this case. Is it even from my code or can it also be caused by vash or another module?
I am using vash v0.7.12-1.
I solved it by increasing the stacktrace limit:
Error.stackTraceLimit = 20;

MEAN.JS: Server username security

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

Resources