-
Notifications
You must be signed in to change notification settings - Fork 2
Create your application
In this tutorial, we'll see:
- What dependencies Crails needs you to install in your system
- How to install Crails on your system
- How to create and launch a simple Crails application
While Crails server completely runs over C++, its asset pipeline and many other utilities are based on guard, a tool that watches files and re-compile your assets, your build targets, or run your tests when changes are detected.
Note that your production server doesn't need to provide ruby. This is only a development dependency. Make sure your development environment provides a version of ruby >= 1.9
.
The first dependency you'll need to provide is a version of Boost >= 1.59
.
Once Boost is installed, you can install the cpp-netlib, the framework that provides our http server.
There are a few other libraries that you may need to install before compiling Crails, if you want to use additional modules. See the respective documentation for each module in order to find out what more you need to install.
Common optional dependencies would be ODB for SQL databases, or Magick++ for image processing.
Using the following commands, you will clone the Crails repository, configure the project, build it and install it on your system.
$> git clone https://github.com/Plaristote/crails.git
$> mkdir crails/build
$> cd crails/build
$> cmake ..
$> make && sudo make install
To create a crails application, use the command crails new [application_name]
. This will create a directory named 'application_name', bootstrap it with all the necessary file to make a crails server, and use bundle install
to prepare your ruby environment.
You may build the application on your own, by going to the build
directory and run the cmake .. && make
command.
You may also build your application from guard
, by launching the crails guard
command, and type the crailscmake
command once guard's prompt appear.
You can then launch your server from your application directory by launching the build/server
command. Your server comes with a few options:
-h, --hostname: the hostname to listen from, defaults to 127.0.0.1
-p, --port: the port to bind, default to 3001,
If you are using an asynchronous server, a few more options are open to you:
-t, --threads: the number of threads to use for the thread-pool,
--ssl: enables ssl
--ssl-cert: the path to your ssl certificate file
--ssl-key: the path to your ssl key file
--ssl-dh: the path to a tmp_dh_file
The server reacts to the INT signal. You may send it using the kill
command, or by typing Ctrl+C
from the console.
Any file in the public
folder can already be served by your application. For instance, public/assets/application.js
would be reachable from http://localhost:3001/assets/application.js
Of course, if you're using a framework, you probably didn't intend to just make a file server. Now that you can create a Crails application, you may go to the next step of the tutorial and learn about how to implement a Router.