LoginSignup
5
5

More than 5 years have passed since last update.

Ruby Simple HTTP Server With Rack

Last updated at Posted at 2012-12-15

Using JavaScript, if it is a static page, Chrome AJAX request local files often problems.

XMLHttpRequest cannot load
file:///*******.
Origin null is not allowed by Access-Control-Allow-Origin.

Because Chrome security mechanisms do not allow AJAX to load local files.
So, I decide to use a new method with ruby.

  • Install the rack, and set rack profiles config.ru:

gem install rack
echo "run Rack::Directory.new('')" > ~/config.ru

  • Switch to any directory and run:

rackup ~/config.ru

If you think the command so long, establish alias alias rp='rackup ~/config.ru'

The default boot server port is 9292,-p [port_num] can modify the port number, now open the browser to get the current directory of the file list: http://locahost:9292/

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5