Skip to content

Rack proxy server for development (Crystal port)

License

Notifications You must be signed in to change notification settings

riseofthetigers/prax.cr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Prax

Rack proxy server for development

This is an attempt to rewrite Prax in Crystal, a Ruby-inspired language that compiles down to C. This should avoid problems with version managers, since Prax would now be a binary application, yet remain as easily hackable as a Ruby application, along with better performances (yay!).

This is in "working" state! Which means that it successfully proxies requests to the Puma and Webrick Rack servers (others are untested).

How it works

  1. resolves *.dev domains to 127.0.0.1 (localhost)
  2. redirects the :80 and :443 ports to :20559 and :20558
  3. receives incoming HTTP requests and extracts the hostname (eg: myapp.dev)
  4. spawns a Rack applications (found at ~/.prax/myapp) if any
  5. proxies the request to the spawned Rack aplication or to the specified port.

.dev TLD

The .dev domain resolver is a NSSwitch extension. You'll may prefer to configure dnsmasq or another local DNS server to resolve .dev domains to 127.0.0.1 or ::1 instead.

This step is crucial: your DNS servers must either always resolve .dev domains to 127.0.0.1 or never resolve them —so the NSSwitch extension will do it. Please troubleshoot with getent hosts myapp.dev (it must return 127.0.0.1) and host myapp.dev (should fail).

Prax also supports http://xip.io domains, so you may use myapp.129.168.0.1.xip.io for example. This is very useful when using an external device like a smartphone or tablet or another computer.

Port Redirections

The port redirections are iptables rules, that are installed and removed using an initd script. The script redirects the port :80 and :443 on 127.0.0.1 and for each wlanX and ethX devices found on your machine, to allow incoming traffic, so you may use xip.io to test on external devices, as mentioned above.

Install

Prax isn't ready for end-user consumption just yet, but if you want to contribute, or feel adventurous, please follow the steps below.

Please note that only Linux is supported. On Mac OS X you'll may want to install Pow!! (for the DNS resolver and the port redirection from :80 to :20559) and then run Prax instead of Pow!!

  1. Install the NSSWitch extension, then restart your browser:

    $ cd ext/ $ make $ sudo make install

  2. Install the iptables rules:

    $ sudo cp install/initd /etc/init.d/prax $ sudo update-rc.d prax defaults $ sudo /etc/init.d/prax start

  3. Either install the Crystal 0.5.9 release, or clone and build the master branch.

  4. Compile Prax:

    $ make

You'll may want to specify the crystal binary to use:

$ make CRYSTAL_BIN=/path/to/crystal/bin/crystal
  1. Prepare Prax environment:

    $ mkdir ~/.prax

  2. Start Prax, and test that it works:

    $ ./bin/prax-binary $ firefox localhost

  3. Link your applications, and enjoy:

    $ cd path/to/myapp $ ln -s $PWD ~/.prax/myapp $ firefox myapp.dev

TODO

Lot of work is still required: evented or thread pool of incoming requests, keepalive connections, proxying websockets, SSL server, etc.

  • logger (to debug prax activity)
  • read .env files before spawning apps
  • handle connections in threads
  • keepalive connections
  • proxy transfer-encoding:chuncked
  • proxy websockets
  • SSL server
  • DEB / RPM packages

Some cleanup redesign:

  • extract Application::Spawner (from Application)
  • extract HTTPProxy (from Prax::Handler)

License

Prax is distributed under the CeCILL 2.1 license. Please see LICENSE for details.

HTML templates for rendering errors are from Pow!!, by Sam Stephenson and Basecamp, and are under the MIT license.

The NSSwitch extension originaly come from Hoof, by pyromaniac, and is under the MIT license.

Authors

About

Rack proxy server for development (Crystal port)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Crystal 65.5%
  • Shell 13.1%
  • Ruby 11.0%
  • HTML 3.7%
  • C 3.6%
  • Makefile 3.1%