puma / puma-dev

A tool to manage rack apps in development with puma
BSD 3-Clause "New" or "Revised" License
1.74k stars 105 forks source link

Feature Request: Allow static files in public directory without rackup file #87

Open rmm5t opened 7 years ago

rmm5t commented 7 years ago

Opening this for discussion. Related to https://github.com/puma/puma-dev/issues/44.

Pow allows you to serve a completely static website as long as it has a public directory. No Gemfile (with puma) nor a rackup file (config.ru) is necessary. This effectively becomes a really easy way to serve a virtual host in development for static sites.

Is it within the scope of puma-dev to more directly mimic this static public directory behavior for completely static sites?

Right now, puma-dev will return an unexpected exit with the following log for a static site with just a public directory and no rackup file.

{"time":"2016-10-20 11:39:47.8902328 -0600 MDT","event":"app_lookup","path":"/Users/me/.puma-dev/myapp"}
{"time":"2016-10-20 11:39:47.893756725 -0600 MDT","event":"booting_app","app":"myapp","socket":"/Users/me/.puma-dev/myapp/tmp/puma-dev-3740.sock"}
{"time":"2016-10-20 11:39:47.893865742 -0600 MDT","event":"waiting_on_app","app":"myapp"}
{"time":"2016-10-20 11:39:49.05906731 -0600 MDT","event":"killing_app","app":"myapp","pid":58675,"reason":"stdout/stderr closed"}
{"time":"2016-10-20 11:39:49.05915872 -0600 MDT","event":"shutdown","app":"myapp"}
{"time":"2016-10-20 11:39:49.059184475 -0600 MDT","event":"lookup_error","error":"unexpected exit"}
{"time":"2016-10-20 11:39:49.059199656 -0600 MDT","event":"dying_on_start","app":"myapp"}
jm3 commented 7 years ago

In lieu of serving bare static sites from public, it would be great to get an example of the minimal config (Gemfile, config.ru β€”Β whatever the bare minimum is that's required) to get a simple static site serving with puma dev.

m5o commented 7 years ago

Managed to run a static page with the following config. As a basement, I used this Heroku Rack setup:

πŸ“– https://devcenter.heroku.com/articles/static-sites-ruby

$ tree static-site
static-site
β”œβ”€β”€ Gemfile
β”œβ”€β”€ config.ru
└─── public
    β”œβ”€β”€ css
    β”‚   └── styles.css
    β”œβ”€β”€ images
    β”‚   └── demo.png
    β”œβ”€β”€ index.html
    └── js
        └── app.js

Additional added gem 'puma' to Gemfile:

# Gemfile

source 'https://rubygems.org'
gem 'rack'
gem 'puma'

config.ru is a copy of the Heroku article

# config.ru

use Rack::Static,
  :urls => ["/images", "/js", "/css"],
  :root => "public"

run lambda { |env|
  [
    200,
    {
      'Content-Type'  => 'text/html',
      'Cache-Control' => 'public, max-age=86400'
    },
    File.open('public/index.html', File::RDONLY)
  ]
}
$ puma-dev link
$ open http://static-site.dev

Page is running, with images, stylesheets, and javascript πŸ‘