I have a simple nodejs api, which connected to mongodb on mlab.
On local I can use GET, POST methods. But after I deployed to Heroku:
I only GET data.
POST method returns 400 bad request. And if I use heroku logs -t I can't see log about post method.
I searched related keywords: heroku -nodejs- post method 400 bad request, they don't work with my case.
This is my log after I use postman send GET and POST requests.
2020-04-01T16:58:02.831314+00:00 app[web.1]: tiny wiz running // my console.log
2020-04-01T16:58:03.131550+00:00 heroku[web.1]: State changed from starting to up
2020-04-01T16:58:03.259355+00:00 app[web.1]: (node:23) DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead.
2020-04-01T16:58:27.099916+00:00 heroku[router]: at=info method=GET path="/" host=MYAPP_URL request_id=a5f384ad-b857-4356-a4de-f8148cfd2e16 fwd="publicIP" dyno=web.1 connect=1ms service=100ms status=200 bytes=1016 protocol=https
2020-04-01T16:58:27.094337+00:00 app[web.1]: GET METHOD HERE!!! // my console.log
▸ Log stream timed out. Please try again.
As you can see, It has no log about POST method.
Pls let's me know if you has any infomation about my environment.
Thank in advance!
Related
`2022-07-27T14:44:04.939800+00:00 heroku[router]: at=info method=POST path="/sales/test/_vti_bin/publishedlinksservice.asmx" host=......herokuapp.com request_id=f3b1c597-25bc-469b-af21-94222743728f fwd="154.160.25.213" dyno=web.1 connect=0ms service=1ms status=404 bytes=462 protocol=https`
I have hosted a node js application on heroku, if I check the logs, there is always a request every 5 to 30 mins to /sales/test/_vti_bin/publishedlinksservice.asmx Does anyone have an idea of what is going on publishedlinksservice.asmx ?
By seeing the log, it actually looks more like an error code.
Analyzing it further, it may be an internal Heroku error as a file on the sales/test/_vti_bin directory was not found as it returns a status=404 on the log.
I do not recognize where this file comes from, but it is a good idea to contact support if you do not recognize this file as well and the issue persists.
I have my app hosted on heroku for nearly 1 year, and in the past 24 hours, it stopped working. I get this in my logs:
2021-11-08T18:15:06.475815+00:00 app[web.1]: [Error: [IBM][CLI Driver] SQL30081N A communication error has been detected. Communication protocol being used: "TCP/IP". Communication API being used: "SOCKETS". Location where the error was detected: "". Communication function detecting the error: "selectForConnectTimeout". Protocol specific error code(s): "115", "*", "*". SQLSTATE=08001
2021-11-08T18:15:06.475827+00:00 app[web.1]: ] {
2021-11-08T18:15:06.475828+00:00 app[web.1]: error: '[node-ibm_db] SQL_ERROR',
2021-11-08T18:15:06.475829+00:00 app[web.1]: sqlcode: -30081,
2021-11-08T18:15:06.475829+00:00 app[web.1]: state: '08001'
2021-11-08T18:15:06.475830+00:00 app[web.1]: }
2021-11-08T18:15:33.386490+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=POST path="/login" host=www.mysite.ca request_id=3d627300-28d2-48af-a86e-60bdb950298a fwd="99.249.30.56" dyno=web.1 connect=0ms service=30000ms status=503 bytes=0 protocol=https
It seems to not like whatever is going on with db2. I can access my database no problem through my local machine, and see everything with in my db tables. I also have this directly from my heroku dashboard.
i am not able to figure out what the issue is. does anyone have any ideas?
Thanks to everyone for their answers. I did some more digging around, and turns out what solved it was reinstalling the db2 driver locally, and pushing it to heroku. Something must have changed that required an update to the db2 driver to connect with the heroku sevrer.
My app is working fine until i try to referesh the page. I made the build version of the frontend and then pasted all the contents in the public folder of node js backend. Everything is working just fine until i do a refresh.
I find a similar problem : Heroku Deployed App, Page Refresh error or Redirecting error
The only difference is i am getting this error: Failed to load resource: the server responded with a status of 404 (Not Found).
I did heroku logs and found this:
2021-01-29T20:31:35.136038+00:00 app[web.1]: GET /posts/myNewsFeed 304
377.308 ms - - 2021-01-29T20:31:35.137763+00:00 heroku[router]: at=info method=GET path="/posts/myNewsFeed"
host=insta-clone-01.herokuapp.com
request_id=d0dfee79-74f4-43c2-9ce5-7df121136872 fwd="1.38.45.193"
dyno=web.1 connect=0ms service=383ms status=304 bytes=181
protocol=https
2021-01-29T20:31:37.519726+00:00 heroku[router]: at=info method=GET
path="/home" host=insta-clone-01.herokuapp.com
request_id=d0a7784f-bcbe-41ed-88de-43e71cd364c7 fwd="1.38.45.193"
dyno=web.1 connect=0ms service=3ms status=404 bytes=400 protocol=https
2021-01-29T20:31:37.520005+00:00 app[web.1]: GET /home 404 1.326 ms -
160
These are the logs for the same page but the first is when i normally get to the page and the second one is when i refresh the page.
what i can say from this is when i am normally trying to get to a page the request is happening to the /posts/myNewsFeed which is my node api endpoint but when i am refreshing the same page the request is happening to /home which is my route for the page ,not the node api endpoint and that's why i am getting the error.
You can see the project here https://github.com/Aditya-shrivastav/InstagramClone
Anyone who can give a solution for this?
I'm sending an error message to the client with status 400 but the logs show Heroku error H18 Server Request Interrupted. I'm logging also the request-id before sending 400 to make sure I'm watching the same request.
heroku[router] info sock=backend at=error code=H18 desc="Server Request Interrupted" method=POST path="/api/v1/email" host=getinvoicesimple.com request_id=b332c22a-78dd-423f-926e-11ae3497d67d fwd="86.150.146.32" dyno=web.1 connect=1ms service=103ms status=503 bytes=267 protocol=https
The app is pretty simple and as it's being aborted before doing anything more complex, I don't see any reason for that.
The entrypoint is a multipart post
router.post('/api/v1/email', function(req, res) {
const appVersion = req.header('x-is-version');
if (!appVersion) {
console.error(`App version is required. ${req.headers['x-request-id']}`)
return res.status(400).send('App must be updated.').end()
}
...
/// The rest of the function
})
I tested it out using npm modules: "node-dev" on the backend.js and "serve" on the root directory of the folder.
I have these 2 guides that tried to help me:
http://www.tilcode.com/deploying-a-mean-stack-app-to-heroku/
and another one from scotch.io "Use MongoDB with a Node.js Application on Heroku"
What I didn't do from the articles that shouldn't matter: in tilcode, it said use to github to generate an SSH key...instead I made one using my mac and a terminal command using some guide.
To summarize my steps:
Login to heroku, create the app
use git commands to add, commit all the files in my github into heroku and pushed them into heroku
I even put the mlab addon and filled out the URI.
It deployed "successfully" but when visiting the app, it says "application failed"
My suspicions:
I do have another working app that uses postgreSQL...but I put it on 'maintenance mode' since my free account only allows for one active dynamo.
Instead of uploading all my node modules, I learned I could have heroku install it like this:
heroku config:set NPM_CONFIG_PRODUCTION=false
I think it may be how I referenced the backend from my frontend javascript.
// var API = 'http://localhost:5000';
var API = 'http://limitless-falls-21423.herokuapp.com';
var app = angular.module('HAL-app', ['ngRoute', 'ngCookies']);
// Some other stuff that came from sandbox app.js
app.directive('whenScrolled', function() {
return function(scope, elm, attr) {
var raw = elm[0];
elm.bind('scroll', function() {
if (raw.scrollTop + raw.offsetHeight >= raw.scrollHeight) {
scope.$apply(attr.whenScrolled);
}
});
};
});
Lastly, when I ran heroku logs --tail I got these messages:
2016-09-05T01:35:27.417956+00:00 app[web.1]: npm ERR! Linux 3.13.0-93-generic
2016-09-05T01:35:27.418339+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2016-09-05T01:35:27.418593+00:00 app[web.1]: npm ERR! node v5.11.1
2016-09-05T01:35:27.418931+00:00 app[web.1]: npm ERR! npm v3.8.6
2016-09-05T01:35:27.419219+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2016-09-05T01:35:27.419386+00:00 app[web.1]: npm ERR! hallocam#1.0.0 start:
node backend.js
2016-09-05T01:35:37.178679+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=limitless-falls-21423.herokuapp.com request_id=4bc9639f-3f64-4c0b-9b0d-d99b967f1b36 fwd="73.54.129.252" dyno= connect= service= status=503 bytes=
******EDIT after Yashua's comment**
I now get a "cannot get" message when visiting the app. Was kinda hesitant about limiting my heroku variables to just the:
NODE_ENV=production
But I guess it makes since since if I keep my mongodb (mongo labs) credentials uploaded and hidden using .gitignore.
Anyway, I'm still thinking it's not "getting" my routes which I have setup my angularjs file like this:
// var API = 'http://localhost:5000'; ##this is the old way to connect my front end factory routes to the backend hosted on 5000
I have it like this right now
var API = 'http://obscure-brook-35938.herokuapp.com/';
I think it may have to look like this:
var API = process.env.PORT
The purpose of the API is to be used for my angular factories like this:
app.factory('backEnd', function($http) {
return {
getSignUp: function(data) {
return $http({
method: 'POST',
url: API + '/signup',
data: data
});
},
getLogin: function(data) {
return $http({
method: 'POST',
url: API + '/login',
data: data
});
},
New Heroku logs --tail
2016-09-05T15:42:52.796464+00:00 heroku[router]: at=info method=GET path="/" host=obscure-brook-35938.herokuapp.com request_id=41fa32e2-42cc-426d-a0d0-ef6755329497 fwd="73.54.129.252" dyno=web.1 connect=1ms service=18ms status=404 bytes=243
2016-09-05T15:42:53.893156+00:00 heroku[router]: at=info method=GET path="/" host=obscure-brook-35938.herokuapp.com request_id=dec235fd-6d54-42e6-b0cc-2f83920d500d fwd="73.54.129.252" dyno=web.1 connect=1ms service=8ms status=404 bytes=243
2016-09-05T15:42:54.602312+00:00 heroku[router]: at=info method=GET path="/" host=obscure-brook-35938.herokuapp.com request_id=8ceb054b-78e9-49b8-bdee-286ca6efcb0d fwd="73.54.129.252" dyno=web.1 connect=1ms service=3ms status=404 bytes=243
Hard to tell offhand but here are some pointers:
I looked at your repo and your package.json is invalid in 2 places. Use a JSON validator.
Secondly your frontend app will not be an issue. You should be able to go to the server URL directly and not have it crashed.
Change your database password if you haven't already. I see that you deleted your mongo_creds.json file but the history is available on GitHub.
The only vars you should need on Heroku is NODE_CONFIG set to production.
I'm closing this thread because it's getting pretty lengthy and a separate problem has arose. As #yashua said, the best way to solve this mongodb/heroku problems is to take it one step at a time. Some tools I've learned from this experience:
If using NPMs to test, that's great as it builds confidence. But to truly test heroku, use its 'heroku local' or 'heroku local web' to test it out locally first (serve it up), then it'll help narrow down further issues when deploying/'git push heroku master'
Build a solid understanding of how .env files work (really, they're
just configuration files to store credential information). I've been
using .json files to store mine, then use .gitignore to stop them
from appearing publicly. Heroku has its own secret keepers in the
form of Procfile and .env
I'm up to a point now where I consolidated my backend/frontend into one root directory. But my frontend and backend use 2 different ports to work when it should only use one. Not sure the best way to approach that since when I do [supposedly] feed them all the same port as 'process.env.MONGOLAB_URI' I get an error that hints that I have it wrong.
2016-09-05T23:36:51.802697+00:00 app[web.1]: /app/node_modules/mongodb/lib/server.js:261
2016-09-05T23:36:51.802698+00:00 app[web.1]: process.nextTick(function() { throw err; })
2016-09-05T23:36:51.802698+00:00 app[web.1]: ^
2016-09-05T23:36:51.803862+00:00 app[web.1]: MongoError: failed to connect to server [#:27017] on first connect
2016-09-05T23:36:51.803864+00:00 app[web.1]: at Pool.<anonymous> (/app/node_modules/mongodb-core/lib/topologies/server.js:313:35)
2016-09-05T23:36:51.803864+00:00 app[web.1]: at emitOne (events.js:96:13)
2016-09-05T23:36:51.803865+00:00 app[web.1]: at Pool.emit (events.js:188:7)
2016-09-05T23:36:51.803865+00:00 app[web.1]: at Connection.<anonymous> (/app/node_modules/mongodb-core/lib/connection/pool.js:260:12)
2016-09-05T23:36:51.803866+00:00 app[web.1]: at Connection.g (events.js:286:16)
2016-09-05T23:36:51.803867+00:00 app[web.1]: at emitTwo (events.js:106:13)
2016-09-05T23:36:51.803867+00:00 app[web.1]: at Connection.emit (events.js:191:7)
2016-09-05T23:36:51.803868+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/mongodb-core/lib/connection/connection.js:162:49)
2016-09-05T23:36:51.803868+00:00 app[web.1]: at Socket.g (events.js:286:16)
2016-09-05T23:36:51.803869+00:00 app[web.1]: at emitOne (events.js:96:13)
2016-09-05T23:36:51.803870+00:00 app[web.1]: at Socket.emit (events.js:188:7)
2016-09-05T23:36:51.803870+00:00 app[web.1]: at connectErrorNT (net.js:1016:8)
2016-09-05T23:36:51.803871+00:00 app[web.1]: at _combinedTickCallback (internal/process/next_tick.js:74:11)
2016-09-05T23:36:51.803871+00:00 app[web.1]: at process._tickCallback (internal/process/next_tick.js:98:9)
2016-09-05T23:36:51.881752+00:00 heroku[web.1]: State changed from starting to crashed
2016-09-05T23:36:51.867426+00:00 heroku[web.1]: Process exited with status 1