LoginSignup
0
0

Azure Static Web Appsで拡張子なしのURLにContent-Typeをつける方法

Last updated at Posted at 2023-09-28

/collections のような拡張子のないパスでjsonを返したいとき、単純にcollectionsというファイルを作成してしまうとContent-Type が application/octet-stream で返ってきてしまいます。

これをapplication/jsonで返したいときは、collections.json というファイルを作成して、元のパスへのリクエストをファイルに rewriteします。

staticwebapp.config.json に以下のように記述します。

staticwebapp.config.json
{
  "routes" : [
    { "route" : "/collections" , "rewrite" : "/collections.json" }
  ]
}

以下のように書いて、できない、できないみたいになっていました。

staticwebapp.config.json
{
  "routes" : [
    { 
      "route" : "/collections" ,
      "headers" : {
        // おそらく、最初に試す。
        "content-type" : "application.json" 
      }
    } 
  ],
  "mimeTypes" : {
    // 次に試す
    "collections" : "application/json" 
  }
}
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