Home » Categories » Multiple Categories |
Geddy.JS: A No-Brainer MVC Node.js Framework |
Article Number: 224 | Rating: Unrated | Last Updated: Sun, Dec 29, 2013 at 10:46 PM
|
IntroductionGeddy is a full stack open source MVC framework based on ruby on rails methodology with built-in authentication module, passportjs and socket.io integration. Creating realtime secure applications in Geddy takes only a few commands; it gives a a very large set of generator commands which work through a command line interface , automating most of the non-trivial tasks such as creating models, controllers, views and even authentication or socket.io integration. In Geddy, you have to only focus on main application logic and let geddy take care of the rest.It also supports a wide range of templates engines, with EJS being the default. You can specify the template engine for a project when creating a new project or resource. Geddy uses Node's built in cluster module which makes use of your multicore processor. So your node.js application is no-longer a single thread application, but leverages multiple cores automatically. InstallationPre-requisites to install nodejs and npm :
If you are using Ubuntu 12.10 or later , you will need to do the following as well:
Add the PPA Repository, which is recommended by Joyent (the maintainers of Node.js):
Update the System package list:
Install Node.js including npm:
Install geddy globally along with jake
Here we install geddy globally so we can use geddy generators. Understanding Geddy StructureEach geddy app being based on MVC principle has a separate directory and files for each: model, controller and views.Geddy GeneratorsGeddy generators are a list of commands available to us to facilitate our development process.Geddy gen command - It is used to generate a new app, model,controller and does various other daily development chores for you.
This will create a geddy app named your_app in a directory named your_app in your working directory .
This will create a resource (model+controller+route) called "profile" with the model having a property name and of type string. If you do not mention the type, it is automatically set to string type .
This command deletes any existing secret and creates a new secret for your application. Session Secret are used to compute hash so without the secret, access to a session would be denied, thus protecting you against session hijacking etc. This commands takes no arguments
This command creates a controller along with an index view and a route to access the controller
This command generates a model with 2 string property called title and content. Here, default property is used when displaying the model. You could have done title:int:default if you wanted an integer type to be default property. In geddy, an ID property is always created and is the default property if none is mentioned. This ID matches the corresponding mongodb document created.
This command scaffolds a resource called personal_detail plus a mockup view of personal_detail where you can add,view, and delete individual entry from the browser itself. When scaffolding, you also have the option to specify the template engine you want to use for the views created.You can use swig, jade, handle or mustache template engine whereas EJS is used if none is mentioned. For example:
Creating an App with Facebook Authentication Built InScaffold a sample application.
Move into the directory.
Scaffold passport.js based authentication into your application. Note: You should not scaffold authentication into an old application as it may override your codes.
Go to developers.facebook.com and get the Secret key of your application by following the steps below. Click on Apps ![]() Click on Create new App (must be registered) ![]() Enter the App Name and other relevant information and click on Continue. ![]() Click on Website with Facebook Login and enter the server's url or IP. You can enter your virtual server's IP like http://192.168.1.2:80/ or enter http://localhost:4000/ if you are testing your application on a localserver. In case you see a different Screen, Click on edit app to reach this screen. Make a Note of the App ID and App Secret and click on save changes. Note: You should never share your App ID and App Secret with anyone. I did it to minimize any confusion. Now go back your server's directory and in the Edupi Folder open config/secrets.json file.
Here, successRedirect is the path which the User will be returned in the case of successful authorization; failure Redirect is the url where the user will be redirected if the authorization fails. Please note that you are only allowed to pass relative links. For example, setting "successRedirect": "http://localhost:4000/login/" will return an error. You can change Both the urls in case you change the routes. Enter AppId as clientID and App Secret as Client Secret as shown below.
You can get twitter and yammer application settings and enter as shown above to get them working. You can search them in case you have any difficulty finding them. Now Save the File and run the server Using
And voila , Now you have facebook integration built into you geddy application. Upon Authentication, two items get added to user's session which are userId (mongodb ID for the user ad authtype which for this case would be facebook). You can check against these variables in your controllers to authenticate a request before it is executed on the virtual server. Going HTTPS in GeddyGeddy supports HTTPS via SSL/TLS or SPDY . To enable it, just add your certificate's details to the configuration file. Key and cert options are required whereas other options that are available for https and spdy module are optional.To add SSL/TLS simply add the following lines to your config file:
To add support for SPDY add the follwing:
Here it is assumed that key.pem and cert.pem are placed in the config folder. And the rest is handled by geddy. Going Into Production ModeCreate a file named app.js with the following content .
And then use Forever to run your server that shall prevent your app from going down TO install forever
And then to start your app, go to the directory containing app.js in terminal and run
And now your app will automatically start in case it crashes. |
Attachments
![]()
There are no attachments for this article.
|
Intermediate Sed: Manipulating Streams of Text in a Linux Environment
Viewed 10057 times since Fri, Dec 27, 2013
How To Set Up mod_security with Apache on Debian/Ubuntu
Viewed 4121 times since Thu, Dec 26, 2013
How To Install Git on Ubuntu 12.04
Viewed 6296 times since Mon, Dec 23, 2013
How To Manage Packages In Ubuntu and Debian With Apt-Get & Apt-Cache
Viewed 6821 times since Fri, Dec 27, 2013
How To Install and Use Memcache on Ubuntu 12.04
Viewed 3566 times since Tue, Dec 24, 2013
How To Install Git on Debian 7
Viewed 2760 times since Fri, Dec 27, 2013
How To Install (LEMP) nginx, MySQL, PHP stack on Arch Linux
Viewed 13686 times since Sun, Dec 29, 2013
Initial Server Setup with Debian 7
Viewed 3719 times since Fri, Dec 27, 2013
How To Create a SSL Certificate on Apache for Ubuntu 12.04
Viewed 3351 times since Mon, Dec 23, 2013
How To Migrate a MySQL Database Between Two Servers
Viewed 2940 times since Thu, Dec 26, 2013
|