-
Notifications
You must be signed in to change notification settings - Fork 18
User Guide
Prax is a proxy server that will start your Web applications then proxy requests and responses back and forth. It will eventually kill applications after a timeout (10 minutes) so they don't clutter your memory forever.
Please note that Prax wouldn't exist without Sam Stephenson's Pow!! All credits go to their work on this fantastic idea. Prax only exists because Pow wouldn't work on Linux.
Prax must be run as a user application, and can't run as root, because then your Rack applications would then be run as root... creating temporary files (at least) that you can't delete without requiring root privileges. Also, we can't bind to ports below 1024 without root privileges. Prax thus starts on the 20559 and 20558 ports.
Having to deal with ports in your applications if more often than not cumbersome: the port is quickly skipped on redirections (especially between domains); etc. Most importantly it would push the burden to the developer just for the sake of development, since we almost never have to deal with ports in production environments.
Prax thus relies on system TCP port redirections instead: a script is run with root privileges that sets iptables rules to redirect traffic on 127.0.0.1
and ::1
for ports 80 and 443 to ports 20559 and 20558. Prax then simply binds to those later ports, and you can transparently access http://myapp.com
and https://myapp.com
without thinking about ports anymore.
Prax links requests to applications using domains and subdomains under the .dev
TLD. For example an application named circles
will be linked as ~/.prax/circles
and will be accessible at http://circles.dev/
Prax will also link any subdomain like http://www.circles.dev or http://ws.services.circles.dev so they are the same unique circles application, but if Prax finds an application at ~/.prax/ws.circles
this application will be used instead of the circles application when accessing http://ws.circles.dev.
Prax also supports the xip.io service —run by Sam Stephenson and Basecamp— which allows testing from another computer, smartphone or tablet from the same local network. Your applications are then accessible at an address like http://circles.192.168.1.10.xip.io
Rack applications are linked into ~/.prax
and require a valid config.ru
. If your config.ru
is invalid, Prax will do its best to report the error. Prax uses rackup
to start your application, and it will rely on the Rack server you defined: thin, puma, ...
For example:
$ cd ~/projects/myapp
$ prax link
$ firefox myapp.dev
Prax supports Bundler, and will start your application using bundle exec rackup
if a Gemfile
can be found. Prax only starts your application, and it won't install your bundle —this is your job. Prax will do it's best to print out the problem, so you should be notified when the application won't start because bundler can't find a new version of a gem after a git pull.
Prax supports forwarding requests to arbitrary ports (bound to localhost). This is particularly useful when dealing with Vagrant boxes, where Prax can't start your applications, but you still want to profit from nice domains and skip HTTP ports.
Create a file in ~/.prax
instead of linking your application, and write it the port number which your application is bound to.
Prax will directly serve files from the public
folder of your application. If your application isn't a Rack application, then Prax will serve files from the root or your project instead. This is great for fully frontend applications that don't need a backend —like an Angular or Ember application.
WARNING: this is untested and likely to not work!
If Prax finds an executable file in ~/.prax
instead of a link or a non-executable file which only contains a port number, then Prax will execute this file, providing a PORT
environment variable, which the Web application must bind on. This should prove useful when dealing with non Ruby applications.
Prax will monitor your applications. If a Rack or Shell applications hasn't been accessed for some time (10 minutes), it will terminate it, so your memory isn't bogged out by applications you don't use.