# Content-Type | Azure Static Web App

So now is about the time that I address what Content-Type is and how it relates to hosting PowerShell files on the internet.  To demonstrate this, I'll create an Azure Static Web App

## Azure Static Web App

Azure Static Web App is a service that can publish a GitHub Repo to an Azure Web using GitHub Actions.  You can learn more at the following links

{% embed url="<https://azure.microsoft.com/en-us/services/app-service/static>" %}

{% embed url="<https://github.com/features/actions>" %}

### Configuration

The configuration is very simple, I used defaults for most settings

![](https://3996045416-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LDKRxGiKLYjW1gana2O%2Fuploads%2FQLyTqvRVrsd1dM6KLeL4%2Fimage.png?alt=media\&token=79b13fa2-7da1-41fd-ae4b-605cd6be23b6)

### GitHub Actions

The first time I ran this it failed because I didn't have an Index.html in the root of my GitHub Repo, so make sure you check the Job for any errors

![](https://3996045416-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LDKRxGiKLYjW1gana2O%2Fuploads%2Ftepwcqjayc9bRaYnzYHk%2Fimage.png?alt=media\&token=6d7bce41-32b0-4a97-8d51-71e2373d827d)

So I simply created a copy of a PowerShell script and saved it as Index.html in the root of my Repo and had the Build and Deploy Job run again

![](https://3996045416-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LDKRxGiKLYjW1gana2O%2Fuploads%2Fc2KO5cDd7zddUdrVtv66%2Fimage.png?alt=media\&token=0190fa32-2d8d-4112-b8f8-7c72b81d3f9c)

## Browser Test

Once the Azure Static Web App build finally completed, my PSCloudScript GitHub Repo was published at the following link

{% embed url="<https://agreeable-river-0b8a1af10.1.azurestaticapps.net>" %}

Opening this in Chrome shows all of the PowerShell formatting is lost

![](https://3996045416-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LDKRxGiKLYjW1gana2O%2Fuploads%2FcnRYHtJqCl6UTBOePjNb%2Fimage.png?alt=media\&token=35e092f4-e85e-40bb-9f5b-4a1961ce9e44)

Additionally, when I navigate to the URL of one of my PowerShell .ps1 files, I'm prompted to download the file instead of viewing the content in Chrome.  This is not the same results that I received when viewing the content on GitHub's Raw links

```
https://agreeable-river-0b8a1af10.1.azurestaticapps.net/Test-PSCloudScriptAzStaticWebApp.ps1
```

The reason why the PowerShell script saved as HTML, and the .ps1 file don't render the same as they do in GitHub Raw is because of the Content-Type.  A quick check of the different URL's with `Invoke-WebRequest` confirms this.  These files are absolutely being rendered based on their Content-Type

```powershell
#Index.html
PS C:\> (Invoke-WebRequest -UseBasicParsing agreeable-river-0b8a1af10.1.azurestaticapps.net).Headers.'Content-Type'
text/html

#Test-PSCloudScriptAzStaticWebApp.ps1
PS C:\> (Invoke-WebRequest -UseBasicParsing agreeable-river-0b8a1af10.1.azurestaticapps.net/Test-PSCloudScriptAzStaticWebApp.ps1).Headers.'Content-Type'
application/octet-stream

#GitHub Raw Test-PSCloudScriptAzStaticWebApp.ps1
PS C:\> (Invoke-WebRequest -UseBasicParsing https://raw.githubusercontent.com/OSDeploy/PSCloudScript/main/Test-PSCloudScriptAzStaticWebApp.ps1).Headers.'Content-Type'
text/plain; charset=utf-8
```

## Azure Static Web App Config

To keep the PowerShell formatting in the .html and the .ps1 file, it is necessary to change the Content-Type to **`text/plain`** (the same as GitHub Raw).  To change this on an Azure Static Web App, I can simply create a file called **`staticwebapp.config.json`** in the root of my GitHub Repo with the following settings

{% code title="staticwebapp.config.json" %}

```json
{
    "mimeTypes": {
        ".htm": "text/plain",
        ".html": "text/plain",
        ".json": "text/json",
        ".md": "text/markdown",
        ".psm1": "text/plain",
        ".ps1": "text/plain"
    }
}
```

{% endcode %}

This configuration change is detailed in Microsoft Docs at the following link

{% embed url="<https://docs.microsoft.com/en-us/azure/static-web-apps/configuration>" %}

After creating the config file and pushing it to GitHub, the GitHub Action will publish the content back to my Azure Static Web.  Another test in Chrome shows the `text/plain` formatting in index.html, and the PowerShell file will now display in the browser rather than prompting for a download

![](https://3996045416-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LDKRxGiKLYjW1gana2O%2Fuploads%2F6JU6dpiXb9mBXD1doMOG%2Fimage.png?alt=media\&token=ae088188-984d-4d3f-9df2-671d4a180dca)

![](https://3996045416-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LDKRxGiKLYjW1gana2O%2Fuploads%2FuufUsiQ3g8Vm1tar53Jv%2Fimage.png?alt=media\&token=528cd317-e06d-463f-9846-a44031ed82fe)

## Summary

If you are publishing PowerShell scripts to a Web Site, make sure you set the Content-Type for the files to **`text/plain`** if you want them displayed and rendered properly in a browser.  Additionally, if you are publishing PowerShell scripts to an **Azure Blob Storage**, you can set the **Content-Type** to **`text/plain`** as needed using **Azure Storage Explorer**

{% embed url="<https://azure.microsoft.com/en-us/features/storage-explorer>" %}

![](https://3996045416-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LDKRxGiKLYjW1gana2O%2Fuploads%2F4doKgM7c6K4Cm04Ngdvv%2Fimage.png?alt=media\&token=430f0cfe-2fac-42a7-8637-59847654c368)

## Sponsor

OSDeploy is sponsored by [Recast Software](https://www.recastsoftware.com/?utm_source=osdeploy\&utm_medium=ad\&utm_campaign=web) and their Systems Management Tools

{% embed url="<https://www.recastsoftware.com/?utm_source=osdeploy&utm_medium=ad&utm_campaign=web>" %}
Sponsored by Recast Software
{% endembed %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.osdeploy.com/guides/pscloudscript/content-type-or-azure-static-web-app.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
