Skip to content

Commit 4a88f47

Browse files
Serve JavaScript and WebAssembly modules by default. (#72)
1 parent c6cb37d commit 4a88f47

4 files changed

Lines changed: 34 additions & 2 deletions

File tree

lib/utopia/static/mime_types.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@ module Static
1616
:media => [
1717
:xiph, "mp3", "mp4", "wav", "aiff", "aac", "webm", "weba", "mov", "avi", "wmv", "mpg", "m3u8", "ts"
1818
],
19+
:scripts => [
20+
"js", "mjs", "wasm"
21+
],
1922
:text => [
20-
"html", "css", "js", "map", "txt", "rtf", "xml", "pdf"
23+
"html", "css", "map", "txt", "rtf", "xml", "pdf"
2124
],
2225
:fonts => [
2326
"otf", "eot", "ttf", "woff", "woff2"
@@ -29,7 +32,7 @@ module Static
2932
"png", "gif", "jpeg", "tiff", "svg", "webp"
3033
],
3134
:default => [
32-
:media, :text, :archive, :images, :fonts
35+
:media, :scripts, :text, :archive, :images, :fonts
3336
]
3437
}
3538

test/utopia/.static/module.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default true;

test/utopia/.static/module.wasm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
WebAssembly

test/utopia/static.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,22 @@
3535
expect(last_response.read).to be == "Uppercase extension!\n"
3636
end
3737

38+
it "serves JavaScript modules" do
39+
client.get "/module.mjs"
40+
41+
expect(last_response.status).to be == 200
42+
expect(last_response.headers["content-type"]).to be == "text/javascript"
43+
expect(last_response.read).to be == "export default true;\n"
44+
end
45+
46+
it "serves WebAssembly modules" do
47+
client.get "/module.wasm"
48+
49+
expect(last_response.status).to be == 200
50+
expect(last_response.headers["content-type"]).to be == "application/wasm"
51+
expect(last_response.read).to be == "WebAssembly\n"
52+
end
53+
3854
it "serves HEAD requests without opening a response body" do
3955
client.head "/test.txt"
4056

@@ -272,10 +288,21 @@
272288

273289
describe Utopia::Static::MIME_TYPES do
274290
let(:extensions) {Utopia::Static::MimeTypeLoader.extensions_for(subject[:default])}
291+
let(:script_extensions) {Utopia::Static::MimeTypeLoader.extensions_for(subject[:scripts])}
292+
293+
it "groups script extensions" do
294+
expect(script_extensions).to have_keys(
295+
".js" => be == "text/javascript",
296+
".mjs" => be == "text/javascript",
297+
".wasm" => be == "application/wasm",
298+
)
299+
end
275300

276301
it "should give the correct mime type" do
277302
expect(extensions).to have_keys(
278303
".txt" => be == "text/plain",
304+
".mjs" => be == "text/javascript",
305+
".wasm" => be == "application/wasm",
279306
".webm" => be == "video/webm",
280307
".weba" => be == "audio/webm",
281308
".ogg" => be == "audio/vorbis",

0 commit comments

Comments
 (0)