How to make vue js ssr using the django framework - django

I want to make some part of my application capable of supporting server rendering. In the project, we actively use vuex and vue router.
We receive all data using api requests
Tell me where to go or provide any working code snippet.
Thank you in advance

An example of an answer might be this. You are creating a fully isolated SPA application with SSR. Django acts only as an API for your application (including you will need to receive data for INITIAL_STATE by API). Next, you start your NodeJs server on any port. Next, you need to configure nginx for redirect requests from port 80 for specific routes to the port of your application.
This is just a theory. Until hands reached a full-fledged example

Related

Run hubot as a part of express app

I have a pretty standard express app, built using the express-generator. Now, I would like to automate some of the things in the app with hubot and I have managed to successfully perform testing and run hubot with slack adapter. However, I would like to have the bot be a part of a regular app.
How can I change the structure of the app (I have a pretty standard import of routes.js which has all of the routes for the app) to allow for the two to run together?
This is running on azure as a WebApp and I have set up a continuous integration with GitHub, so I pretty much just push code and it gets deployed, I don't run anything manually on the actual server. I would be able to run the hubot and server it on a different subdomain or path on the app if it was a regular VPS, but since the azure is taking care of those things, I would need the hubot somehow baked-in the actual express app.
As I know, Hubot has a build-in express web framework that can serve HTTP requests. So theoretically you can integrate hubot with your express webapp thru the router dispatch different urls between express app and hubot.
As references, there is a experimental package project hubot-express shows that hubot as a express app startup. you can try to refer to the code https://github.com/hubot-scripts/hubot-express/blob/master/src/hubot-express.coffee to implement the integration.
The key code: robot.express = app = express();
And the article "Automation and Monitoring with Hubot" show the code that how to serving http requests, please move to https://leanpub.com/automation-and-monitoring-with-hubot/read#leanpub-auto-serving-http-requests to review it.
The key code: robot.router.post('/hubot/notify/:room', function(req, res) {...});
To add to this, in the end I moved to botkit library that provides way easier and integrated way to have both the server and the actual app.

Running a meteor app as part of a wider django project

I'm currently working on a project which would require some realtime functionalities such as Multi-user chatrooms etc.
Ideally, I’m looking to have meteor run the chat application(on a different port) and mongodb act as message broker to the django back-end which would take care of user registration , management and everything 'non-realtime' related.
This would involve setting up a reverse-proxy which would redirect to a different port based on the url (please let me know if i'm wrong in this)
Would this be possible(or even advisable)? Another option would be to implement the same with tornado. but I have no experience with building tornado-based apps and rather do this with a framework I’m comfortable with.
Thanks,
You can have Django serve the Meteor front-end while providing access to its data using django-ddp, giving you some distinct advantages:
Continue to serve your existing Django project/apps.
No extra services or ports to manage.
Scale out by simply adding more front-end Python/Django servers (server to server IPC is done via the existing database connection).
Use django.contrib.auth user accounts in your Meteor app.
Familiar Python/Django code (no "callback" style such as with Tornado).
Use time-tested, trusted relational databases.
Use Django migrations to effectively manage schema changes.
There's a Gitter chat room where I can give you assistance if you need it.
DISCLAIMER: I'm the author of django-ddp.
A meteor application is more than capable of handling the user registration flow and many other things. Why not just build the application entirely in meteor? Your application sounds like a perfect candidate for meteor, with realtime interaction with your database at the core.
The other option would be to use swampdragon which adds realtime data binding within django. It allows for simple bi directional communication between the server and the client. Again, essential for a chat application. It nice and easy to get setup and running as well.
Are there any specific reasons to not implementing your application in one framework alone?

Cloning PyQt app in django framework

I've designed a desktop app using PyQt GUI toolkit and now I need to embed this app on my Django website. Do I need to clone it using django's own logic or is there a way to get it up on website using some interface. Coz I need this to work on my website same way it works as desktop. Do I need to find out packages in django to remake it over the web or is there way to simplify the task?
Please help.
I'm not aware of any libraries to port a PyQT desktop app to a django webapp. Django certainly does nothing to enable this one way or another. I think, you'll find that you have to rewrite it for the web. Django is a great framework and depending on the complexity of your app, it might not be too difficult. If you haven't done much with web development, there is a lot to learn!
If it seemed like common sense to you that you should be able to run a desktop app as a webapp, consider this:
Almost all web communication that you likely encounter is done via HTTP. HTTP is a protocol for passing data between servers and clients (often, browsers). What this means is that any communication that takes place must be resolved into discrete chunks. Consider an example flow:
You go to google in your browser.
Your browser then hits a DNS server (or cache) that resolves the name google.com to some IP address.
Cool, now your browser makes a request to that IP address and says "get me some stuff".
Google decides to send you back a minimal amount of HTML and lots of minified JavaScript in the page.
Your browser realizes that there are some image links in the HTML and so it makes additional requests to google to get each of the images so that it can display them.
Now all the content is loaded on your browser so it starts to execute the JavaScript code, and that code needs some more data from google so it starts sending requests to google too.
This is just a small example of how fundamentally different a web application operates than how a desktop application does. On a desktop app you have the added convenience that any operation doesn't need to be "packaged up" and sent, then have an action taken, etc (unless you're using a messaging architecture, but that's relatively uncommon outside of enterprise apps).

Test a webservice on a different port locally without JSONP

I'm currently writing a webservice (with node.js) for an AngularJS frontend which is hosted with node.js
It will later be available through a proxy under domain.com/api and therefore I don't need JSONP.
For local testing purposes i have my AngularJS app running on localhost:80 and my node.js backend on localhost:3000. Naturally I'm not able to query json requests. The easies
What would be the best setup to test my homepage locally without screwing to much in my setup?
I'm currently working on windows. Linux is also an option if it is easier.
Would it be possible to write a simple proxy for express that hosts both apps in the same domain?
You can use the hosts file to set the domain.com/api to localhost. This is done in /etc/hosts in Linux, but its present somewhere in Windows too. Another thing that helps me a lot is ssh tunneling. You can, for example, tunnel remote ports (where your backend is running) to localhost with ssh -L localPort:your.server:remotePort
It's not exactly what you asked for, but the easiest might be to have the node.js app serve the AngularJS app, too. It's quite efficient, certainly efficient enough to use for development.
If it's an expressjs app, you can just add
app.use(express['static'](__dirname + "/public"));
before your other routes to have it look for static files in ./public/
If your app is served by a template or build system that you can't easily reproduce in node.js, then another option would be to run nginx, apache or haproxy on some port (80 or 5000 or ...) and have that proxy to the current backend server for the app and port 3000 (the node.js app) for the API/data requests.
You might even be able to have your server currently running on port 80 do this.
As a final idea you could also setup the node.js app to proxy to port 80 for the "app files".
Edit - I just realized that both of your apps are written in node.js. Would it be possible to set it up so you run them separately in production but together in development? Put all the real functionality in modules and then have three separate "loaders" that start the apps, one together and then a loader for each individually.

Getting node.js and Django on same domain

For a brief overview/desciption, I am using Django as the bread and butter for a webapp. I want to add a bunch of "real-time" features to the app. More so then I can do with stuff like Torndao or django-socketio. So what I would like to do is take the full dive and use Django with node.js. Basically, Django will get all the data and and handle all the accounts. Then when a piece of data changes, it will send a message using AMQP which will route the message to node.js. Node.js will then use socket.io to get the fresh data to the browser.
My question is how to get the two to play together. Specifically, how can I get both on the same domain so that when the client connects to
var socket = io.connect('http://thedomain.com');
it will be dealt with by node.js and all the other requests will go to Django? Also, I would ideally like to have the Django app running on Heroku as a standalone app and have the node.js also running on Heorku on the standalone app, if possible. Any tips or pointers would be greatly appreciated! Thanks!