【发布时间】:2012-03-12 05:08:23
【问题描述】:
如何设置 config.ru 文件以使 Pow 在公共目录之外提供 html/css/js 文件?假设我想从 html 文件夹中为它们提供服务。
【问题讨论】:
如何设置 config.ru 文件以使 Pow 在公共目录之外提供 html/css/js 文件?假设我想从 html 文件夹中为它们提供服务。
【问题讨论】:
您可以使用rack-contrib 中的TryStatic:
require 'rack/contrib/try_static'
use Rack::TryStatic,
:root => "html",
:urls => %w[/]
如果您只想在开发期间添加 if ENV['RACK_ENV'] == 'development'(例如,如果您的 Web 服务器配置为从 html/ 提供服务),您可能需要添加 if ENV['RACK_ENV'] == 'development'
.
【讨论】:
TryStatic 没有自动加载到rack/contrib.rb 中,试试require 'rack/contrib/try_static';查看我的更新答案。