I am trying to deploy server side of MERN app on heroku but got stuck on code=H12 desc="Request timeout", even though the message "DB was successfully connected" from mongoose.connect() method, is shown, so I have whitelisted IPs on mongoDB Atlas, but still can't find the issue.
Thank you,
Related
I keep receiving this error on Heroku:
UnhandledPromiseRejectionWarning: MongooseServerSelectionError: Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you're trying to access the database from an IP that isn't whitelisted. Make sure your current IP address is on your Atlas cluster's IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/
I have already added 0.0.0.0 and my own IP address to Atlas.
This is how I am connecting (using Mongoose):
// link mongoose
mongoose.connect(process.env.DB_LINK, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
});
I have already added the DB_LINK to a config variable on Heroku.
Everything works great on localhost. I'm unsure as to why this does not work. I also get this error at the end:
at=error code=H12 desc="Request timeout"
I appreciate the help!
Ok i'll give more detailed answer as described in #Jack comment section.
1. Go to the Network Access section
2. Click add IP address button on the right section
3. Click allow access from anywhere.
Total noob here, and currently learning node.js and all the fun it can procure.
I am wrote a REST API with node/express, with a database in mongoDB (and mongoose in my code).
The database is a free one hosted on AWS (through the mongoDB website).
I am calling the following endpoint :https://rewaer-backend.herokuapp.com/api/users/ with postman.
Here is how the route look like:
// GET all users
router.get("/", async (req, res) => {
try {
const user = await User.find();
res.json(user);
}
catch (err) {
res.status(400).json({ message: err });
}
});
but I a getting the following error from heroku:
2020-10-07T14:39:58.684608+00:00 heroku[router]: at=error code=H12
desc="Request timeout" method=POST path="/api/users/"
host=rewaer-backend.herokuapp.com
request_id=94d50342-514e-45e7-94ad-5cb1acde44fa fwd="37.120.11.242"
dyno=web.1 connect=1ms service=30001ms status=503 bytes=0
protocol=https
My collection "users" has only two set of data. Also, really small. When running the server in local (connected to the DB on AWS) this works fine. As you can see in my code, I should be returning something, even if an err happens. So no reason to timeout here.
The Heroku logs show that the connection to the db is successful.
I have no idea what is not working here, and google was not able to help me any further: hence me asking the real wise people ;)
Thanks a lot for any help,
Clément
The default server selection timeout in MongoDB drivers is 30 seconds. Heroku also has a 30 second timeout in its routing layer for the app server to produce the response.
Change server selection timeout to a lower value.
Then fix MongoDB connectivity issues you have (likely IP whitelist).
I wrote a simple GraphQL server using Apollo Express and deployed it to Heroku. After some messing around with Procfiles and the like, it built OK.
When I hit the main URL https://limitless-atoll-59109.herokuapp.com I get the error
Cannot GET /
OK, then I thought the Express server must just be looking for a get on the graphql endpoint. But when I hit https://limitless-atoll-59109.herokuapp.com/graphql I get
GET query missing.
Do I need to include a port in the url? I've got the port set correctly in the code
const PORT = process.env.PORT || 4000
app.listen({port: PORT}, () =>
console.log(`Server ready at http://localhost:${PORT}${server.graphqlPath}`)
);
but I don't think I need to include it when accessing the server on Heroku, do I?
For what it's worth, this is the error in the error logs
019-05-08T17:07:41.492327+00:00 heroku[router]: at=info method=GET
path="/graphql" host=limitless-atoll-59109.herokuapp.com
request_id=b6171835-aac4-4b45-8a7b-daebbb3167ed fwd="139.47.21.74"
dyno=web.1 connect=0ms service=900ms status=400 bytes=196
protocol=https
Thanks for any help!
The answer is that it is the url that ends in /graphql that one wants. However, when you hit that url from the browser, it attempts to load the playground, and fails, as the playground is disabled by default in production.
However, you can make graphql calls against that url from your client app and it works fine.
If you are using apollo server you can just enable it in production:
const server = new ApolloServer({
typeDefs,
resolvers,
introspection: true,
playground: true,
});
I write telegram bot and use Telegraf library.
I placed my bot on Heroku.
I set up webhooks this way:
app.telegram.setWebhook(`${URL}/bot${BOT_TOKEN}`);
app.startWebhook(`/bot${BOT_TOKEN}`, null, PORT);
But in Heroku logs I see
at=info method=POST path="/bot" host=my-app.herokuapp.com request_id=a8f99998-5e9b-4fe4-9af6-9ac56e492ae3 fwd="149.154.167.206" dyno=web.1 connect=3ms service=4ms status=403 bytes=101 protocol=https
getWebhookInfo() also log last_error_message: 'Wrong response from the webhook: 403 Forbidden.
Trying test example from telegram webhook guide with postman also return 403
SOLUTION: I solved it by addition Express to my script like in this example
The 403 forbidden error code mostly happens if your bot has no access to what he´s trying to reach. An example could be that you called the sendmessage function with a user_id and not a chat_id or that your bot has no access to the chat (kicked/ banned).
As you were a little short on code, my answer could turn out to be not 100% accurate.
Edit: Here is a link to the official telegram error documentation of the error. Maybe that could be of additional help for you.
Scaling my web app to 2 web proceses on Heroku breaks Nowjs/Sockets.io.
I'm using full stack that is new to me and everything works great until I add a 2nd web process. Node.js still responds fine but Nowjs stops responding. I get 503 responds in the browser and
GET musicbacon.com/socket.io/1/?t=1339117661910 dyno=web.2 queue=0 wait=0ms service=2ms status=200 bytes=82
2012-06-08T01:07:42+00:00 heroku[router]: Error H13 (Connection closed without response) -> GET musicbacon.com/socket.io/1/websocket/12401614301555103827 dyno=web.2 queue= wait= service= status=503 bytes=
on the server.
I think that Nowjs (which is an abstraction layer on top of Socket.io) creates it's own server along side my Node.js server. Scaling Heroku spins up a new Node.js server VM but since Now.js isn't yet compatible with distributed environments it just dies.
Hopefully I'm missing something and I can scale Now.js because 1 Heroku web process can only handle about 60 users at a time in my experience.
Full stake is:
Heroku
Node.js
Express
Jade
Now.js
Postgres
Error H13 reference: https://devcenter.heroku.com/articles/error-codes#h13__connection_closed_without_response
WebSockets don't work on Heroku, you need to change your Socket.IO configuration to disable WS:
https://devcenter.heroku.com/articles/using-socket-io-with-node-js-on-heroku
https://devcenter.heroku.com/articles/request-timeout#longpolling_and_streaming_responses
https://github.com/LearnBoost/Socket.IO/wiki/Configuring-Socket.IO