Azure / static-web-apps

Azure Static Web Apps. For bugs and feature requests, please create an issue in this repo. For community discussions, latest updates, kindly refer to the Discussions Tab. To know what's new in Static Web Apps, visit https://aka.ms/swa/ThisMonth
https://aka.ms/swa
MIT License
323 stars 55 forks source link

Unable to serve RESX files #918

Open hajekj opened 1 year ago

hajekj commented 1 year ago

Describe the bug

When publishing a static application which contains .resx files, attempting to download them will result in a 404 error.

To Reproduce Steps to reproduce the behavior:

  1. Visit https://zealous-field-0ddb22503-preview.westeurope.1.azurestaticapps.net/sample.resx
  2. The RESX doesn't download, and you are presented with a 404

Expected behavior A clear and concise description of what you expected to happen.

The file should download.

Screenshots N/A

Device info (if applicable): N/A

Additional context

I also tried explicitly specifying MIME type for it, but no change. This is currently blocking us from migrating to Static Web Apps. In Storage Static Web it works fine.

I also noticed some really weird behavior:

I have navigationFallback set to index.html but whenever I try to visit something like: https://zealous-field-0ddb22503-preview.westeurope.1.azurestaticapps.net/thisfilereallydoesntexist.resx, I still get 404 instead of my index.html.

hajekj commented 1 year ago

I noticed that this is also happening when hosting .resx on App Service, because .resx is explicitly disallowed in applicationHost.config. In App Service, I managed to mitigate this issue by adding the following into my applicationHost.xdt file.

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <system.webServer>
    <security>
      <requestFiltering>
        <fileExtensions>
          <add fileExtension=".resx" allowed="true" xdt:Transform="Replace" xdt:Locator="Match(fileExtension)" />
        </fileExtensions>
      </requestFiltering>
    </security>
  </system.webServer>
</configuration>

However, this doesn't work for Static Web Apps.

thomasgauvin commented 1 year ago

@mkarmark this is blocking @hajekj & his implementation, any chance we can investigate enabling these file extensions?

Kargo commented 7 months ago

I'm having the same problem with .cs files. Any updates on this?

thomasgauvin commented 7 months ago

Hi @kargo, looking to learn more about the use case for hosting .cs files, what are they being used for? Would help understand the need for caching/etc.

Kargo commented 7 months ago

@thomasgauvin, the company I work for is using Azure Static Web Apps to host our developer documentation site. We're using snippets from .cs files for code blocks in examples, but we would also like to link to the full file.

We're using MkDocs to generate the documentation site.

I've tried setting the mime-type for the .cs files to text/plain in our staticwebapp.config.json to no avail. If I add a rewrite rule for each file I can get Azure to serve the file by omitting the file type. However that isn't scalable as we have many files and adding a rewrite rule for each route is cumbersome.

{
  "routes": [
    {
      "route": "/assets/example/Program",
      "rewrite": "/assets/example/Program.cs"
    }
  ],
  "mimeTypes": {
    ".cs": "text/plain"
  }
}
hajekj commented 5 months ago

@thomasgauvin - any update on this please?