Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/utopia/static/mime_types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ module Static
:media => [
:xiph, "mp3", "mp4", "wav", "aiff", "aac", "webm", "weba", "mov", "avi", "wmv", "mpg", "m3u8", "ts"
],
:scripts => [
"js", "mjs", "wasm"
],
:text => [
"html", "css", "js", "map", "txt", "rtf", "xml", "pdf"
"html", "css", "map", "txt", "rtf", "xml", "pdf"
],
:fonts => [
"otf", "eot", "ttf", "woff", "woff2"
Expand All @@ -29,7 +32,7 @@ module Static
"png", "gif", "jpeg", "tiff", "svg", "webp"
],
:default => [
:media, :text, :archive, :images, :fonts
:media, :scripts, :text, :archive, :images, :fonts
]
}

Expand Down
1 change: 1 addition & 0 deletions test/utopia/.static/module.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default true;
1 change: 1 addition & 0 deletions test/utopia/.static/module.wasm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
WebAssembly
27 changes: 27 additions & 0 deletions test/utopia/static.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@
expect(last_response.read).to be == "Uppercase extension!\n"
end

it "serves JavaScript modules" do
client.get "/module.mjs"

expect(last_response.status).to be == 200
expect(last_response.headers["content-type"]).to be == "text/javascript"
expect(last_response.read).to be == "export default true;\n"
end

it "serves WebAssembly modules" do
client.get "/module.wasm"

expect(last_response.status).to be == 200
expect(last_response.headers["content-type"]).to be == "application/wasm"
expect(last_response.read).to be == "WebAssembly\n"
end

it "serves HEAD requests without opening a response body" do
client.head "/test.txt"

Expand Down Expand Up @@ -272,10 +288,21 @@

describe Utopia::Static::MIME_TYPES do
let(:extensions) {Utopia::Static::MimeTypeLoader.extensions_for(subject[:default])}
let(:script_extensions) {Utopia::Static::MimeTypeLoader.extensions_for(subject[:scripts])}

it "groups script extensions" do
expect(script_extensions).to have_keys(
".js" => be == "text/javascript",
".mjs" => be == "text/javascript",
".wasm" => be == "application/wasm",
)
end

it "should give the correct mime type" do
expect(extensions).to have_keys(
".txt" => be == "text/plain",
".mjs" => be == "text/javascript",
".wasm" => be == "application/wasm",
".webm" => be == "video/webm",
".weba" => be == "audio/webm",
".ogg" => be == "audio/vorbis",
Expand Down
Loading