LoginSignup
0
0

More than 5 years have passed since last update.

JavaScriptのES6の拡張子.mjsのモジュールファイルをNginxで送る方法

Last updated at Posted at 2018-01-28

背景

ブラウザで動くjavascriptエディター jsnoteを作っていた. ES6のmoduleのファイルの拡張子を.mjsにしたら、Nginxで送れなかった.

問題

mine typeが合わないからファイルを送れないとconsole画面で言われる.
nginxのmine.typesというファイルを見ると次のように書いてあった.

/etc/nginx/mine.types
types {
    text/html                             html htm shtml;
    text/css                              css;
    text/xml                              xml;
    image/gif                             gif;
    image/jpeg                            jpeg jpg;
    application/javascript                js;
    application/atom+xml                  atom;
    application/rss+xml                   rss;

対処法

mine.typesを/etc/nginx/conf.dの下にコピーして, application/javascriptにmjsを加える.

/etc/nginx/conf.d/mine.types
types {
    text/html                             html htm shtml;
    text/css                              css;
    text/xml                              xml;
    image/gif                             gif;
    image/jpeg                            jpeg jpg;
    application/javascript                js mjs;
    application/atom+xml                  atom;
    application/rss+xml                   rss;
    .
    .
    .

さらに、nginxのconfファイルの中でmine.typesをincludeする.

/etc/nginx/conf.d/server.conf
server {
  listen 80 default_server;
  server_name server.com;
  include /etc/nginx/conf.d/mime.types;

  location / {
    root /usr/share/nginx/html;
    index index.html;
  }
}

サンプルコード

jsnoteで使っているコード
GitHub

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0