How to refresh the website with Nancy if model data changed? - nancy

If my model data is changing how to refresh the site automatically to display the changed data?
Is this possible at the server or do I have to write some client code for this?
Thanks for helping.
Michael

You have to write client side code to do this, the server has no relationship with the client once its sent the response - the connection is closed, the server moves on to other requests.
You need to use Javascript to poll the server and update based on server side changes - you can use a data binding framework such as Knock Out, or a larger framework such as Angular to make this easier.
SignalR may help you here, in that its a system which plugs into both the client and server side, keeps open a connection so you can send data to the client side instantly from the server.

Related

Why Content download need so much time?

I am using firestore with queries and i am getting data but something in network tab is loading none stop
as you can see its over a minute
should i be concerned about it?
It's hard to be certain without seeing the code that produces this problem, but most likely you're using a realtime listener (onSnapshot) in your code.
Such a listener keeps an active , open connection between the client and the server, so that the database can send a notification to the client when the data changes. The Chrome network tool shows this as a content download, because indeed data trickles in over this connection.
So likely what you're seeing is a normal part of Firestore's protocol for realtime, bi-directional communication between the client and server, but again.

Connect to Mongodb from Angular, from where?

I have this admin panel template that's built in nodejs, jquery and angular.
I am trying to connect it to a mongodb to make simple CRUD operations.
I've installed mongojs via npm for this purpose but how do I take it from here? The Datebase itself is already set up and ready for use.
I tried to follow the instructions but I am not quite sure where to put the code that connects to the database.
var databaseUrl = "mydb"; // "username:password#example.com/mydb"
var collections = ["users", "reports"]
var db = require("mongojs").connect(databaseUrl, collections);
I've understood that it has to be on the server side as the client side won't run the require('mongojs') part. But in what file should it preferably be placed? And if it's put in the server side code how do I reach the 'db' object from the client side when making the CRUD operations?
Thanks in advance!
The server and the clients are different devices that interact by HTTP. Consider them as different projects that can luckily execute same chunks of code just because they are written in the same language. DB connection is not this kind of chunk.
Client doesn't connect to the database. You can't give db access to all your clients. Actually db should not be accessible from the Internet at all for security reasons.
Client makes HTTP requests to the server. Server fetches the db data and returns it back to the client. It is the main purpose of almost all servers.
This data updates the state of the models in your controller code.

How to sync with server data by AngularJS?

Angular has two ways data binding which is cool, so I just wonder if it could be sync in Server-Client binding? For example, usually we would request data by $http
$http.get(apiURL)
.then(function(rsp){
console.log('getRsp', rsp);
});
I hope it could send request automatically once server side (inside database for example) changes.
In tranditionally, we can use timeout, but it is kind old way, and watsting resource. What if we can listen the server change? But how?!
You can achiece this by using socket.io. Both on server and client side. By using timeout all of the clients will repeatedly keep on calling the server even if there is no update. With sockets you can keep a channel open between server and client. The server will only notify the client whenever there is a change in the data.
You can find a lot tutorials for sockets on the internet.

How does Firebase's Firebase.on() work?

How does Firebase.on() work? It's suppose to "Listen for data changes at a particular location", according to https://www.firebase.com/docs/web/api/query/on.html
,but how does the client know when to update itself? Is the client also a lightweight server that listens to the Firebase server or does the client automatically do an update every x seconds?
The Firebase client keeps a connection open to the server. Depending on where your app runs, this can either be a web socket or a so-called long-polling connection. Either of these ensures that the server can send new data to the client as soon as it is available.
The client listens for changes on the server and you need to update the client data (your objects) in the event callback.
As a suggestion, this can be greatly simplified with firesync.

Sails server side views and socket for client updates (in angular)

Struggling to get my head around this functionality.
I use a sails server view to host a simple find for a given model in the DB.
When browsing to: url/model I get the html view that populates the data.
So far so good.
My view is handled by angular and have databinding between the visible data and what came from the server (ejs).
Now, I want the data to change dynamically with sockets on the client view.
Reading the code and the docs, it seems I need to have the client view, actually get the data to be able to subscribe to it on the server side. (This handled in blueprints, or manually if I want to in a controller method).
The problem is that I will be querying the data twice in the DB.
Once in the server hosted view with the default HTTP handled blueprint, and then
Twice when I actually have to get the data via sockets.
I managed to only do this once, if my client is standalone, by simply querying the data via sockets only.
But how can I do both ? Server hosted views and data, with subscription to sockets for updates, without having to get the data twice ?
Thx.

Resources