How to make Angular2 Http.get to wait indefinitely? - node.js

I am working on an electron app with Angular2 for frontend. When user reaches the home page, angular starts a http.get service which initiates a hardware device which waits for user input in form of RFID cards. When user response is triggered then express returns the GET call with data. User event may occur from a few seconds to few hours. It works fine if user responds quickly but after a couple of minutes Angular doesn't show the response.
I am sorry for the unclear question details. I don't know what code to add. Any help would be highly appreciated.

Related

Discord API Rate Limiting

I am currently creating a web-dashboard for a Discord bot I have made previously.
I am using express.js as my backend server, and in order to validate user's credentials, almost every request made whether it is a get or post request, has some sort of call to the Discord API originating from the backend of the dashboard before the frontend is served to the user (as I do not know how I can securely make API requests from the frontend as user tokens are required)
As you can probably guess from the previous paragraph, I have been temporarily banned from using the API (below), meaning I can no longer use my Discord Account and my bot has gone offline.
Image showing API error (Code 429)
I understand that the API request sends headers regarding the rate limits and remaining quota etc, I just don't know what to do with that data. What would be the best programming practices in order to solve this rate-limiting issue?
I have tried using the refresh tokens initially, as I thought new tokens would stop users having to re-authenticate. These tokens were stored in a mongodb database (to prevent me from sending a token request every time a user wanted to make a request), but these measures did not help as much as I would have liked them to.
You shouldn't be experiencing rate limits that quickly, why are you making so many requests to the API? The access token provided from OAuth2 flow works for multiple requests (it stays valid for a full week if you don't ask for a new token), so make sure you aren't requesting a new token every time the client loads your app.
If the problem is that you're using the access token to make a request to the Discord API for user info every time the user reloads your app, then you need to change that. Just save user info on your backend, and every once in a while (maybe a minute or two), "refresh" their data automatically by making just one request. That way if somebody spam reloads your app, your app won't then spam request the Discord API for new info every time.
If you are ever ratelimited by Discord because your users spam reloaded your app, that's a vulnerability on your end and you need to handle it.
Also, you mentioned using the rate limiting info provided in the request headers. That info can be useful so that you know how long to wait before making another request, and stop Discord's API from acting up towards your app. But it definitely wouldn't help in actually stopping your app from getting ratelimited, that can only be helped by managing how you make requests to the Discord API better.

Pusher showing already sent data

I'm using pusher for a python-vuejs app.
I have a function that sends data to the pusher, the data content is {'message':{'value':id_value}}
The function is executed via an api rest POST request, when I trigger the function and send the data to the pusher on the page with the url host/data-url the pusher console shows the correct informations for the first time.
When I execute the POST request again (without refreshing the page), the data is gotten twice (gotten means that it is physically there not just a pusher console output), if i do the request again it is gotten 3 times and so on.
Does anyone have any idea on how to initialize pusher after each request or something because if I refresh the page and send the data, it works again and i get it only once.
I figured it out if anyone have the same problem.
1.You should subscribe the moment you call the page.
2.If you are triggering the channel.bind with a button click (or any event launcher ) , make sure to unbind before the click and not after.

Dialogflow bug webhook node js facebook chatbot

create a chatbot with dialogflow and a webhook with node js. Sometimes requests do not reach the webhook and others it takes more than five seconds to respond. It's something that happens randomly and that forces me to use intent's responses. what is this about? How can I improve it?
I have deployed it in heroku, on my pc with ngrok and on a server that has ngnix, the bug still happens. What I do is send a value to the webhook to validate it or send it to an api rest. It's very random of 20 tests that I do happen about five times. Has something similar ever happened to you?
Sometimes I only send the value to validate that is greater than or equal to x and that it is number, most of the times it works, returns the next question of the dialog in others the chatbot does not respond to the user. It seems that the webhook rejects the request.

Getting very slow ajax responses when requesting product page

I'm building a Chrome extension for the steam community, and this extension has some functions to get the user games list and scrap their product page to get some information about every game.
Any of the requests done by the extension to the API is almost instant, but when I try to load an app page (like for example http://store.steampowered.com/app/440/ ), the response is delayed up to 40s.
At the end, the page loads and the ajax request is successful, but the waiting times are just too high.
I have noticed that this behaviour is not consistent, and on other computers with the same exact extension code and internet connection theresponse is instant, and on the same computer with other browsers the delay is not there either.
Why could this happen? I'm not starting multiple ajax calls, and the extension waits before finishing a call before making the next one.
Please, see attached image
Thanks

Call server in background

I'm building an iPhone-app in which the logged in users can chat to each other. It's very like the Wordfeud chat for example. You click a user and a modal view controller shows up where you chat.
I have set up a push notification server that works, I just need to know just how I should use it.
When the chat view controller is open I poll in the background with ASIHttpRequest every tenth second to see if a message has been sent from the user you chat with. This works perfectly fine.
But what happends when i close the chat view controller to do something else in the app. Should I create a ASIHttpRequest in every single view controller in the app to poll for new messages or is it here the push notification service takes over? Even though the app is still open?
Or shouldn't I send push notifications when the app is running, only when it's not running?
If that's the case I guess I have to send a request to the server which says that the app is has now been closed (here is a problem if the app crashed out of the blue).
I would be really greatful for some guidelines here, I have searched the web but there are old discussions which confuses me, and some new ones where many people says different.

Resources