diff --git a/lib/utopia/static/mime_types.rb b/lib/utopia/static/mime_types.rb index e2586142..ed1e9bae 100644 --- a/lib/utopia/static/mime_types.rb +++ b/lib/utopia/static/mime_types.rb @@ -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" @@ -29,7 +32,7 @@ module Static "png", "gif", "jpeg", "tiff", "svg", "webp" ], :default => [ - :media, :text, :archive, :images, :fonts + :media, :scripts, :text, :archive, :images, :fonts ] } diff --git a/test/utopia/.static/module.mjs b/test/utopia/.static/module.mjs new file mode 100644 index 00000000..ff3177ba --- /dev/null +++ b/test/utopia/.static/module.mjs @@ -0,0 +1 @@ +export default true; diff --git a/test/utopia/.static/module.wasm b/test/utopia/.static/module.wasm new file mode 100644 index 00000000..c34a9e48 --- /dev/null +++ b/test/utopia/.static/module.wasm @@ -0,0 +1 @@ +WebAssembly diff --git a/test/utopia/static.rb b/test/utopia/static.rb index 32978d4a..6922057e 100755 --- a/test/utopia/static.rb +++ b/test/utopia/static.rb @@ -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" @@ -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",