2010-07-22 53 views
8

我想讓Rack提供特定內容類型的特定文件。它是一個.htc文件,它需要作爲text/x-component使用,以便IE能識別它。在阿帕奇我只是做如何使用Rack爲特定文件設置內容類型?

AddType text/x-component .htc 

我怎樣才能實現這一點與機架?目前該文件由Rack :: Static提供,但我沒有找到設置內容類型的選項。

回答

13

您可以更新config/initializers/mime_types.rb這樣的:

# Be sure to restart your server when you modify this file. 

# Add new mime types for use in respond_to blocks: 
# Mime::Type.register "text/richtext", :rtf 
# Mime::Type.register_alias "text/html", :iphone 

Rack::Mime::MIME_TYPES.merge!({ 
    ".ogg"  => "application/ogg", 
    ".ogx"  => "application/ogg", 
    ".ogv"  => "video/ogg", 
    ".oga"  => "audio/ogg", 
    ".mp4"  => "video/mp4", 
    ".m4v"  => "video/mp4", 
    ".mp3"  => "audio/mpeg", 
    ".m4a"  => "audio/mpeg", 
    ".htc"  => "text/x-component" 
}) 
+0

這奏效了,謝謝!我沒有mime_types.rb,所以我把它直接放到config.ru文件中。 – 2010-07-22 14:27:40

+0

對不起,確定你沒有一個,它來自鐵軌,但由於鐵軌是一個架子,它的工作原理。 – jigfox 2010-07-22 15:26:22

+0

通常我的Rack項目沒有config/initializers目錄,只有我的rails項目有... – Phillipp 2016-06-30 17:05:46

0

或者只是回答的問題,在config/initializers/mime_types.rb補充一點:

Mime::Type.register "text/x-component", :htc 
相關問題