Skip to content

Commit a8f8f7e

Browse files
committed
fix: Provide correct mime type for javascript and css
The correct mimetype for javascript is a requirement when loading javascript modules#
1 parent be15cfd commit a8f8f7e

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/internal/servlet/AwsServletContext.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ public String getMimeType(String s) {
136136
if (mimeTypes == null) {
137137
mimeTypes = new MimetypesFileTypeMap();
138138
}
139+
if (s.endsWith(".css")) {
140+
return "text/css";
141+
}
142+
if (s.endsWith(".js")) {
143+
return "application/javascript";
144+
}
139145
// TODO: The getContentType method of the MimetypesFileTypeMap returns application/octet-stream
140146
// instead of null when the type cannot be found. We should replace with an implementation that
141147
// loads the System mime types ($JAVA_HOME/lib/mime.types

aws-serverless-java-container-core/src/test/java/com/amazonaws/serverless/proxy/internal/servlet/AwsServletContextTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ void getMimeType_mimeTypeOfCorrectFile_expectMime() {
7070
mimeType = ctx.getMimeType("file://" + tmpFilePath);
7171
assertEquals("text/plain", mimeType);
7272
}
73+
@Test
74+
void getMimeType_mimeTypeOfJavascript_expectApplicationJavascript() {
75+
String tmpFilePath = TMP_DIR + "some.js";
76+
AwsServletContext ctx = new AwsServletContext(null);
77+
String mimeType = ctx.getMimeType(tmpFilePath);
78+
assertEquals("application/javascript", mimeType);
79+
}
7380

7481
@Test
7582
void getMimeType_unknownExtension_expectAppOctetStream() {

0 commit comments

Comments
 (0)