Simple command-line HTTPS server for the .NET Core CLI
Switch branches/tags
Nothing to show
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Add stale-bot configuration Sep 28, 2018
.vscode Update README and dependencies for 0.2.0 release Mar 12, 2018
docs Improve docs May 11, 2018
src Replace AppVeyor and Travis with Azure Pipelines Nov 4, 2018
test/dotnet-serve.Tests Disable code coverage. It does weird things to the environment which … Nov 4, 2018
.editorconfig Add license headers and update .editorconfig Mar 17, 2018
.gitattributes Ensure test assets have expected line endings Nov 4, 2018
.gitignore Update to aspnetcore 2.1.0-preview2, don't pack ref assemblies, and a… Apr 5, 2018
CHANGELOG.md Update CHANGELOG for 1.1.0 [ci skip] Oct 18, 2018
CONTRIBUTING.md Initial commit Dec 13, 2017
Directory.Build.props Replace AppVeyor and Travis with Azure Pipelines Nov 4, 2018
Directory.Build.targets Replace AppVeyor and Travis with Azure Pipelines Nov 4, 2018
LICENSE.txt Initial commit Dec 13, 2017
NuGet.config Update aspnet dependency to 2.1.0 May 25, 2018
README.md Replace AppVeyor and Travis with Azure Pipelines Nov 4, 2018
azure-pipelines.yml Replace AppVeyor and Travis with Azure Pipelines Nov 4, 2018
build.ps1 Ensure the code-signed tag gets set on CI Nov 4, 2018
dotnet-serve.sln Replace AppVeyor and Travis with Azure Pipelines Nov 4, 2018
dotnet-serve.sln.licenseheader Add license headers and update .editorconfig Mar 17, 2018
releasenotes.props Implement authenticode signing and nuget package signing Oct 18, 2018
version.props Replace AppVeyor and Travis with Azure Pipelines Nov 4, 2018

README.md

dotnet-serve

Build Status

NuGet MyGet

A simple command-line HTTP server.

It launches a server in the current working directory and serves all files in it.

Get started

Download the .NET Core SDK 2.1.300 or newer. Once installed, 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

Usage

Usage: dotnet serve [-d|--directory <DIR>] [-o|--open-browser] [--version]
                    [-p|--port <PORT>] [-a|--address <ADDRESS>]
                    [--path-base <PATH>] [--default-extensions[:<EXTENSIONS>]]
                    [-q|--quiet] [-v|--verbose] [-S|--tls] [--cert] [--key]
                    [--pfx] [--pfx-pwd] [-m|--mime <MIME>] [-?|-h|--help]

Options:
  --version                          Show version information
  -d|--directory <DIR>               The root directory to serve. [Current directory]
  -o|--open-browser                  Open a web browser when the server starts. [false]
  -p|--port <PORT>                   Port to use [8080]. Use 0 for a dynamic port.
  -a|--address <ADDRESS>             Address to use [127.0.0.1]
  --path-base <PATH>                 The base URL path of postpended to the site url.
  --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.
  -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 <EXT>=<MIME>             Add a mapping from file extension to MIME type. Empty MIME removes a mapping.
  -?|-h|--help                       Show help information

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 and private.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