Add-KrFileServerMiddleware
SYNOPSIS
Registers a file server to serve static files from a specified path.
SYNTAX
Items (Default)
Add-KrFileServerMiddleware [-Server <KestrunHost>] [-RootPath <String>] [-RequestPath <String>]
[-HttpsCompression <HttpsCompressionMode>] [-ServeUnknownFileTypes] [-DefaultContentType <String>]
[-EnableDirectoryBrowsing] [-RedirectToAppendTrailingSlash] [-ContentTypeMap <Hashtable>] [-NoCache]
[-NoStore] [-MaxAge <Int32>] [-SharedMaxAge <Int32>] [-MaxStale] [-MaxStaleLimit <Int32>] [-MinFresh <Int32>]
[-NoTransform] [-OnlyIfCached] [-Public] [-Private] [-MustRevalidate] [-ProxyRevalidate] [-PassThru]
[<CommonParameters>]
Options
Add-KrFileServerMiddleware [-Server <KestrunHost>] -Options <FileServerOptions> [-NoCache] [-NoStore]
[-MaxAge <Int32>] [-SharedMaxAge <Int32>] [-MaxStale] [-MaxStaleLimit <Int32>] [-MinFresh <Int32>]
[-NoTransform] [-OnlyIfCached] [-Public] [-Private] [-MustRevalidate] [-ProxyRevalidate] [-PassThru]
[<CommonParameters>]
DESCRIPTION
This cmdlet allows you to serve static files from a specified path using the Kestrun server. It can be used to serve files like images, stylesheets, and scripts.
EXAMPLES
EXAMPLE 1
$server | Add-KrFileServerMiddleware -RequestPath '/files' -EnableDirectoryBrowsing
This example adds a file server to the server for the path '/files', enabling directory browsing.
The file server will use the default options for serving static files.
EXAMPLE 2
$server | Add-KrFileServerMiddleware -Options $options
This example adds a file server to the server using the specified FileServerOptions.
PARAMETERS
-Server
The Kestrun server instance to which the file server will be added.
Type: KestrunHost
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False
-Options
The FileServerOptions to configure the file server.
Type: FileServerOptions
Parameter Sets: Options
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-RootPath
The root path from which to serve files.
Type: String
Parameter Sets: Items
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-RequestPath
The path at which the file server will be registered.
Type: String
Parameter Sets: Items
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-HttpsCompression
The HTTPS compression mode to use for the static files.
Type: HttpsCompressionMode
Parameter Sets: Items
Aliases:
Accepted values: Default, DoNotCompress, Compress
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-ServeUnknownFileTypes
If specified, allows serving files with unknown MIME types.
Type: SwitchParameter
Parameter Sets: Items
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
-DefaultContentType
The default content type to use for files served by the static file service.
Type: String
Parameter Sets: Items
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-EnableDirectoryBrowsing
If specified, enables directory browsing for the file server.
Type: SwitchParameter
Parameter Sets: Items
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
-RedirectToAppendTrailingSlash
If specified, requests to the path will be redirected to append a trailing slash.
Type: SwitchParameter
Parameter Sets: Items
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
-ContentTypeMap
A hashtable mapping file extensions to MIME types (e.g., @{ “.yaml”=”application/x-yaml”; “.yml”=”application/x-yaml” }). This allows for serving files with the correct `Content-Type` header.
Type: Hashtable
Parameter Sets: Items
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-NoCache
If specified, adds a ‘no-cache’ directive to the Cache-Control header.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
-NoStore
If specified, adds a ‘no-store’ directive to the Cache-Control header.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
-MaxAge
If specified, sets the ‘max-age’ directive in seconds for the Cache-Control header.
Type: Int32
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: 0
Accept pipeline input: False
Accept wildcard characters: False
-SharedMaxAge
If specified, sets the ‘s-maxage’ directive in seconds for the Cache-Control header (used by shared caches).
Type: Int32
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: 0
Accept pipeline input: False
Accept wildcard characters: False
-MaxStale
If specified, adds a ‘max-stale’ directive to the Cache-Control header.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
-MaxStaleLimit
If specified, sets the limit in seconds for the ‘max-stale’ directive in the Cache-Control header.
Type: Int32
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: 0
Accept pipeline input: False
Accept wildcard characters: False
-MinFresh
If specified, sets the ‘min-fresh’ directive in seconds for the Cache-Control header.
Type: Int32
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: 0
Accept pipeline input: False
Accept wildcard characters: False
-NoTransform
If specified, adds a ‘no-transform’ directive to the Cache-Control header.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
-OnlyIfCached
If specified, adds an ‘only-if-cached’ directive to the Cache-Control header.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
-Public
If specified, adds a ‘public’ directive to the Cache-Control header.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
-Private
If specified, adds a ‘private’ directive to the Cache-Control header.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
-MustRevalidate
If specified, adds a ‘must-revalidate’ directive to the Cache-Control header.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
-ProxyRevalidate
If specified, adds a ‘proxy-revalidate’ directive to the Cache-Control header.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
-PassThru
If specified, the cmdlet will return the modified server instance.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.