dotnet-serve
1.10.175
dotnet tool install --global dotnet-serve --version 1.10.175
dotnet new tool-manifest # if you are setting up this repo dotnet tool install --local dotnet-serve --version 1.10.175
#tool dotnet:?package=dotnet-serve&version=1.10.175
nuke :add-package dotnet-serve --version 1.10.175
dotnet-serve
A simple command-line HTTP server.
It launches a server in the current working directory and serves all files in it.
Get started
Install .NET 6 or newer and run this command:
dotnet tool install --global dotnet-serve
Start a simple server and open the browser by running
dotnet serve -o
..and with HTTPS.
dotnet serve -o -S
... with a specific port (otherwise, it defaults to a random, unused port).
dotnet serve --port 8080
... with access allowed to remote machines (defaults to loopback only.) Use this if running inside Docker.
dotnet serve --address any
Usage
Usage: dotnet serve [options]
Options:
--version Show version information.
-d|--directory <DIR> The root directory to serve. [Current directory]
-o|--open-browser[:<PATH>] Open a web browser when the server starts. [Default false]
You can also provide the subpath to launch by using -o:<PATH>.
Example: -o:/path/index.html
-p|--port <PORT> Port to use [8080]. Use 0 for a dynamic port.
-a|--address <ADDRESS> Address to use. [Default = localhost].
Accepts IP addresses,
'localhost' for only accept requests from loopback connections, or
'any' to accept requests from any IP address.
--path-base <PATH> The base URL path of postpended to the site url.
--reverse-proxy <MAPPING> Map a path pattern to another url.
Expected format is <SOURCE_PATH_PATTERN>=<DESTINATION_URL_PREFIX>.
SOURCE_PATH_PATTERN uses ASP.NET routing syntax. Use {**all} to match anything.
--default-extensions[:<EXTENSIONS>] A comma-delimited list of extensions to use when no extension is provided in the URL. [.html,.htm]
-q|--quiet Show less console output.
-v|--verbose Show more console output.
-h|--headers <HEADER_AND_VALUE> A header to return with all file/directory responses. e.g. -h "X-XSS-Protection: 1; mode=block"
-S|--tls Enable TLS (HTTPS)
--cert A PEM encoded certificate file to use for HTTPS connections.
Defaults to file in current directory named 'cert.pem'
--key A PEM encoded private key to use for HTTPS connections.
Defaults to file in current directory named 'private.key'
--pfx A PKCS#12 certificate file to use for HTTPS connections.
Defaults to file in current directory named 'cert.pfx'
--pfx-pwd The password to open the certificate file. (Optional)
-m|--mime <MAPPING> Add a mapping from file extension to MIME type. Empty MIME removes a mapping.
Expected format is <EXT>=<MIME>.
-z|--gzip Enable gzip compression
-b|--brotli Enable brotli compression
-c|--cors Enable CORS (It will enable CORS for all origin and all methods)
--save-options Save specified options to .netconfig for subsequent runs.
--config-file Use the given .netconfig file.
--fallback-file The path to a file which is served for requests that do not match known file names.
This is commonly used for single-page web applications.
-?|--help Show help information.
Tip: single letters for options can be combined. Example:
dotnet serve -Sozq
Configuring HTTPS
dotnet serve -S
will serve requests over HTTPS. By default, it will attempt to find an appropriate certificate
on the machine.
By default, dotnet serve
will look for, in order:
- A pair of files named
cert.pem
andprivate.key
in the current directory - A file named
cert.pfx
in the current directory - The ASP.NET Core Developer Certificate (localhost only)
You can also manually specify certificates as command line options (see below):
See also this doc for how to create a self-signed HTTPS certificate.
.pem files
Use this when you have your certficate and private key stored in separate files (PEM encoded).
dotnet serve --cert ./cert.pem --key ./private.pem
Note: currently only RSA private keys are supported.
.pfx file
You can generate a self-signed
Use this when you have your certficate as a .pfx/.p12 file (PKCS#12 format).
dotnet serve --pfx myCert.pfx --pfx-pwd certPass123
Using the ASP.NET Core Developer Certificate
The developer certificate is automatically created the first time you use dotnet
.
When serving on 'localhost', dotnet-serve will discover and use when you run:
dotnet serve -S
Reverse Proxy
dotnet-serve --reverse-proxy /api/{**all}=http://localhost:5000
will proxy all requests matching /api/*
to http://localhost:5000/api/*
.
The source path pattern uses ASP.NET routing syntax. See the ASP.NET docs for more info.
Multiple --reverse-proxy <MAPPING>
directives can be defined.
Reusing options with .netconfig
dotnet-serve
supports reading and saving options using dotnet-config,
which provides hierarchical inherited configuration for any .NET tool. This means you can save your
frequently used options to .netconfig
so you don't need to specify them every time and for every
folder you serve across your machine.
To save the options used in a particular run to the current directory's .netconfig
, just append
--save-options
:
dotnet serve -p 8080 --gzip --cors --quiet --save-options
After running that command, a new .netconfig
will be created (if there isn't one already there)
with the following section for dotnet-serve
:
[serve]
port = 8000
quiet
gzip
cors
header = X-My-Option: foo
header = X-Another: bar
(note multiple header
, mime
type mappings and exclude-file
entries can be provided as
individual variables)
You can place those settings in any parent folder and it will be reused across all descendent
folders, or they can also be saved to the global (user profile) or system locations. To easily
configure these options at those levels, use the dotnet-config
tool itself:
dotnet config --global --set serve.port 8000
This will default the port to 8000
whenever a port is not specified in the command line. You
can open the saved .netconfig
at %USERPROFILE%\.netconfig
or ~/.netconfig
.
The cert
, key
and pfx
values, in particular, can be relative paths that are resolved
relative to the location of the declaring .netconfig
file, which can be very convenient.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
This package has no dependencies.
Version | Downloads | Last updated |
---|---|---|
1.10.175 | 8,492,261 | 3/30/2024 |
1.10.172 | 6,934,996 | 6/28/2023 |
1.10.168 | 76,804 | 6/25/2023 |
1.10.162 | 5,359 | 6/25/2023 |
1.10.158 | 3,226 | 6/25/2023 |
1.10.155 | 2,564,681 | 2/4/2023 |
1.10.149 | 1,716,345 | 10/8/2022 |
1.10.140 | 588,728 | 9/15/2022 |
1.10.128 | 1,491,031 | 6/28/2022 |
1.10.112 | 831,084 | 4/24/2022 |
1.10.93 | 6,312 | 2/1/2022 |
1.10.82 | 6,012 | 11/28/2021 |
1.9.71 | 4,714 | 9/25/2021 |
1.8.34 | 8,352 | 3/4/2021 |
1.8.31 | 3,267 | 3/4/2021 |
1.8.26 | 3,502 | 3/4/2021 |
1.8.25 | 3,699 | 3/4/2021 |
1.8.15 | 46,748 | 1/31/2021 |
1.7.141 | 5,185 | 12/3/2020 |
1.7.140 | 3,444 | 12/3/2020 |
1.7.139 | 6,701 | 11/6/2020 |
1.7.138 | 3,363 | 11/6/2020 |
1.7.137 | 4,227 | 10/1/2020 |
1.7.136 | 3,632 | 9/5/2020 |
1.7.135 | 3,622 | 9/2/2020 |
1.7.134 | 3,561 | 9/2/2020 |
1.7.133 | 3,680 | 8/30/2020 |
1.7.132 | 4,741 | 7/17/2020 |
1.7.131 | 4,083 | 6/28/2020 |
1.7.130 | 3,472 | 6/28/2020 |
1.7.125 | 207,695 | 5/2/2020 |
1.7.124 | 3,365 | 4/25/2020 |
1.7.123 | 3,136 | 4/25/2020 |
1.7.122 | 3,830 | 4/11/2020 |
1.7.121 | 3,387 | 4/11/2020 |
1.7.120 | 4,158 | 3/15/2020 |
1.7.119 | 3,902 | 2/29/2020 |
1.7.116 | 3,732 | 2/11/2020 |
1.6.0 | 15,295 | 12/4/2019 |
1.5.0 | 92,910 | 10/22/2019 |
1.4.1 | 4,174 | 9/21/2019 |
1.4.0 | 3,578 | 9/20/2019 |
1.3.0 | 4,026 | 8/29/2019 |
1.2.0 | 6,355 | 2/25/2019 |
1.1.0 | 5,219 | 10/18/2018 |
1.0.0 | 5,663 | 5/30/2018 |
0.4.1 | 4,522 | 5/11/2018 |
0.4.0 | 4,653 | 5/11/2018 |
0.3.0 | 4,756 | 4/11/2018 |
0.2.1 | 4,626 | 3/28/2018 |
0.2.0 | 4,787 | 3/12/2018 |
0.1.0 | 1,980 | 12/13/2017 |