Run hubot as a part of express app - regex

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.

Related

How to make vue js ssr using the django framework

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

New web application technology

We're about to start a new project and I've been looking at some of the new web technologies. We want to build a RESTful api which a client can access. To date we've been using python with django/flask to build the api and using jquery for the front end.
I've read quite a bit on javascript frameworks such as emberjs and angular, as well as nodejs solutions like express, meteor and derby. I really like the idea that a site should 'auto update' when the model changes.I'm aware that there are some libraries like gevent which can help facilitate socket level communication, but it seems to be more of a patch than an elegant solution.
Ideally, I don't want to give up a proven technology, ie writing server code in python (or php,ruby whatever) for building my whole app on nodejs. Having a RESTful API is important since we want our services to be open and accessible.
Would it be a bad idea to have 2 servers and 1 client? 1 traditional api server communicating with a javascript framework on the client. Then also run a nodejs server alongside the api server which can somehow talk to the api and if it finds updates, passes it along to the client.
We want to build a RESTful api which a client can access.
Ideally, I don't want to give up a proven technology, ie writing server code in python (or php,ruby whatever) for building my whole app on nodejs.
Then you should probably go with Rails and Ember.js. I'll quote eviltrout (co-founder of discourse) which is build on ember and rails:
One amazing side effect of a rich client side app is you end up with a battle tested API. Our app has consumed our own API since day one, so we know it works.
If we want to create a native client for Android or iOS, it would be a lot easier because we already speak JSON fluently. If people want to build services that use Discourse, they won’t have to result to screen scraping. It’s a huge win for us and the developers that use our platform. 1
However you should keep in mind that ember is as of to date still a very young framework (rc3 v1.0.0).
I don't know what sort of application you are building (in respect to why you would want to use node) How to decide when to use Node.js?

Apache/wsgi/django configuration

We have two django applications running on the same server that interact with an API that uses oauth. They function as expected, communicating with each other, when run under the django development server. However, when deployed using apache/wsgi they don't work together.
(To be more specific, one application is an instance of the Indivo server; the other one is a custom application that interacts with Indivo.)
What is the best way to trouble shoot this?
Make sure that the Django instances are working by themselves first. For example, one app could be started under Apache, and the other using ./manage.py runserver. Reverse which one is running using Apache and verify that all works as expected.
Use the Apache error logs to look for errors such as failed requests.
Since one of your apps appears to implement a web API, use something like the Google Chrome Postman App to exercise the site from a web browser.
Learn how to use the Django logging framework to log information about your apps as they execute.

Accessing a django-piston REST API via a django view within the same project

I'm building a small web service. To showcase what the service can do I am going to build a lite-weight interface. I'm having a hard time figuring out how my REST API and regular Django views can play nicely together.
Here's my setup:
Using django-piston to build a simple CRUD REST web service.
Using Django views with httplib2 to GET/POST to/from that web service.
Both are being run from the same Django project (and thus same web server).
Right now I have simple read REST service working in the browser. But when I try to use httplib2 from the Django view the request just hangs.
My questions:
-Am I thinking about this the right way?
-Is there a better way to accomplish this?
-Should my REST web service be a different project (and web server) than my REST interface?
Any help would be greatly appreciated!
Generally, I'd demonstrate an API working via unit tests, rather than live views, but can see how that might not be what you need.
So (in line with akonsu's comment above) if you're experiencing this problem local dev, it's the single threaded devserver that's blocking the API from running while the view is executing.
Have you tried a multi-threaded version of the runserver? Like this one?

Building web services without a web server

OK, this is impossible, but I will try to explain the situation here.
Let's say we have cases, that we need a fast setup of a web server in order to have a simple soap web service running (querying a db and so on).
In VS though, upon debugging a web project, it creates a quick ASP.NET development server without relying on the actuall IIS that might be installed on the PC.
Is there any project that does something like that?
This would be ideal for small projects, where a simple executable would get a server ready to go and would allow web services to be executed right away.
I have looked at some stuff over the net like http://msdn.microsoft.com/en-us/magazine/cc163879.aspx and http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2004/05/24/4479.aspx but they seem to be quite outdated and i am not sure how well they work (havent tested them thoroughly)
EDIT: I have build an application like the one you suggest. However, how can i implement HTTP GET/POST requests to the service using this method? I tried using WebGet after my operationcontract but it didnt work. For example, my service is at http://localhost:8080/Service and i would like to use it such as http://localhost:8080/Service/getMethod?x=2.
I believe that the development server used by Visual Studio is based off of the Cassini code base (of which there is a fork here). I also found this article on hosting the asp.net runtime. It was also created a while back (2004), but has been updated since (2008). I think a lot of the core concepts are probably still the same.
Another approach would be a roll-your-own web server using the HttpListener class. This could take some work if you want to use it for hosting asmx type services, but if you were doing RESTful services, it isn't too bad of an option (this is actually how RavenDB works if you are not hosting it under IIS).
A WCF service can be hosted in almost any kind of application, including a Windows Service or a console application. There is no need for a web server at all.
Alright,
i've done it so im posting it here to help anyone who has issues with similar problems.
Create your WCF Service file as usual and then by using ServiceHost (or WebServiceHost) you can easily create a WCF service.
In order to use GET http requests to make it simple to communicate with mobile devices (such as iphone) you can use WebGet above your service methods and make sure you manually add a service endpoint using WebHttpBinding for WebServiceHost or WebHttpBinding with an WebHttpBehavior for ServiceHost.
Then you can call your service methods such as http://localhost:port/webhttpendpointaddress/mymethod?x=2.