Skip to content

Commit

Permalink
text/javascript MIME type for .mjs in Nginx config
Browse files Browse the repository at this point in the history
This is compliant with RFC 9239.

The normal .js extension remains on application/javascript as defined in the OEM mime.types config.

See https://trac.nginx.org/nginx/ticket/2216 for upstream change proposal.

Closes #737

GUS-W-16142337
  • Loading branch information
dzuelke committed Jul 1, 2024
1 parent 01f9583 commit 26de5cf
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 32 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### CHG

- Sync Nginx `mime.types` config with upstream to add `application/wasm` for `.wasm` and `image/avif` for `.avif` files (#738) [David Zuelke]
- Add MIME type `text/javascript` for `.mjs` files to Nginx config as per RFC 9239; `application/javascript` remains for `.js` from upstream default `mime.types` (#737) [David Zuelke]

## [v253] - 2024-06-13

Expand Down
1 change: 1 addition & 0 deletions conf/nginx/heroku.conf.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
http {
include mime.types;
include heroku.types;
default_type application/octet-stream;

#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
Expand Down
9 changes: 9 additions & 0 deletions conf/nginx/heroku.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# this file is separate from mime.types to allow easier syncing with upstream
types {
# mime.types still defines "application/javascript" for "js"
# We only define "mjs" here to avoid duplicate extension warnings on startup.
# In compliance with RFC 9239, we are using "text/javascript" for "mjs"
# If and when upsteam ever update their default config, we can drop this.
# Also see https://trac.nginx.org/nginx/ticket/2216
text/javascript mjs;
}
63 changes: 36 additions & 27 deletions test/spec/nginx_spec.rb
Original file line number Diff line number Diff line change
@@ -1,35 +1,44 @@
require_relative "spec_helper"

describe "A PHP application" do
it "installs a recent stable nginx with OpenSSL support and expected modules" do
new_app_with_stack_and_platrepo('test/fixtures/default').deploy do |app|
nginx = app.output.match(/- nginx \((\d+\.\d*[02468]\.\d+)/)
expect(nginx).not_to be_nil, "expected nginx install line in build output"
expect(Gem::Dependency.new('nginx', '~> 1.14').match?('nginx', nginx[1])).to be == true, "expected nginx version compatible with selector '~> 1.14' but got #{nginx[1]}"
retry_until retry: 3, sleep: 5 do
nginx_v = app.run('nginx -V')
expect(nginx_v).to match(/^built with OpenSSL/)
expect(nginx_v).to match(/--with-http_auth_request_module/)
expect(nginx_v).to match(/--with-http_realip_module/)
expect(nginx_v).to match(/--with-http_ssl_module/)
expect(nginx_v).to match(/--with-http_stub_status_module/)
end
end
end
it "allows access to /.well-known/ with Nginx" do
new_app_with_stack_and_platrepo('test/fixtures/default').tap do |app|
describe "A PHP application using Nginx" do
before(:all) do
@app = new_app_with_stack_and_platrepo('test/fixtures/default').tap do |app|
app.before_deploy(:append) do
FileUtils.mkdir_p(".well-known/acme")
File.open(".well-known/acme/foo", "w+") do |f|
f.write 'bar'
end
File.open("Procfile", "w+") do |f|
f.write 'web: heroku-php-nginx'
end
end
app.deploy do |app|
expect(successful_body(app, path: '/.well-known/acme/foo')).to eq 'bar'
File.write(".well-known/acme/foo", "bar")

FileUtils.touch("test.mjs")

File.write("Procfile", "web: heroku-php-nginx")
end
end

@app.deploy
end

after(:all) do
@app.teardown!
end

it "gets a recent stable Nginx with OpenSSL support and expected modules" do
nginx = @app.output.match(/- nginx \((\d+\.\d*[02468]\.\d+)/)
expect(nginx).not_to be_nil, "expected nginx install line in build output"
expect(Gem::Dependency.new('nginx', '~> 1.14').match?('nginx', nginx[1])).to be == true, "expected nginx version compatible with selector '~> 1.14' but got #{nginx[1]}"
retry_until retry: 3, sleep: 5 do
nginx_v = @app.run('nginx -V')
expect(nginx_v).to match(/^built with OpenSSL/)
expect(nginx_v).to match(/--with-http_auth_request_module/)
expect(nginx_v).to match(/--with-http_realip_module/)
expect(nginx_v).to match(/--with-http_ssl_module/)
expect(nginx_v).to match(/--with-http_stub_status_module/)
end
end

it "allows access to /.well-known/" do
expect(successful_body(@app, path: '/.well-known/acme/foo')).to eq 'bar'
end

it "serves a .mjs file with MIME type text/javascript" do
expect(successful_request(@app, path: '/test.mjs').get_header('Content-Type')).to eq 'text/javascript'
end
end
8 changes: 6 additions & 2 deletions test/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,16 @@ def product_hash(hash)
end
end

def successful_body(app, options = {})
def successful_request(app, options = {})
retry_limit = options[:retry_limit] || 5
retry_interval = options[:retry_interval] || 2
path = options[:path] ? "/#{options[:path]}" : ''
web_url = app.platform_api.app.info(app.name).fetch("web_url")
Excon.get("#{web_url}#{path}", :idempotent => true, :expects => 200, :retry_limit => retry_limit, :retry_interval => retry_interval).body
Excon.get("#{web_url}#{path}", :idempotent => true, :expects => 200, :retry_limit => retry_limit, :retry_interval => retry_interval)
end

def successful_body(app, options = {})
successful_request(app, options).body
end

def expect_exit(expect: :to, operator: :eq, code: 0)
Expand Down
2 changes: 1 addition & 1 deletion test/var/log/parallel_runtime_rspec.heroku-20.log
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ test/spec/composer-2_spec.rb:90
test/spec/devcenter_spec.rb:5
test/spec/httpd_spec.rb:18
test/spec/newrelic_spec.rb:115
test/spec/nginx_spec.rb:49
test/spec/nginx_spec.rb:25
test/spec/php-7.3_base_spec.rb:30
test/spec/php-7.3_boot-apache2_spec.rb:65
test/spec/php-7.3_boot-nginx_spec.rb:55
Expand Down
2 changes: 1 addition & 1 deletion test/var/log/parallel_runtime_rspec.heroku-22.log
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test/spec/composer-2_spec.rb:90
test/spec/devcenter_spec.rb:5
test/spec/httpd_spec.rb:18
test/spec/newrelic_spec.rb:115
test/spec/nginx_spec.rb:49
test/spec/nginx_spec.rb:25
test/spec/php-8.1_base_spec.rb:30
test/spec/php-8.1_boot-apache2_spec.rb:65
test/spec/php-8.1_boot-nginx_spec.rb:55
Expand Down
2 changes: 1 addition & 1 deletion test/var/log/parallel_runtime_rspec.heroku-24.log
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test/spec/composer-2_spec.rb:90
test/spec/devcenter_spec.rb:5
test/spec/httpd_spec.rb:18
test/spec/newrelic_spec.rb:115
test/spec/nginx_spec.rb:49
test/spec/nginx_spec.rb:25
test/spec/php-8.2_base_spec.rb:30
test/spec/php-8.2_boot-apache2_spec.rb:65
test/spec/php-8.2_boot-nginx_spec.rb:55
Expand Down

0 comments on commit 26de5cf

Please sign in to comment.