All Projects → natemcmaster → Dotnet Serve

natemcmaster / Dotnet Serve

Licence: apache-2.0
Simple command-line HTTPS server for the .NET Core CLI

Projects that are alternatives of or similar to Dotnet Serve

Sqlite Global Tool
SQLite .NET Core CLI tool that allows the user to manually enter and execute SQL statements with or without showing query result.
Stars: ✭ 37 (-92.31%)
Mutual labels:  command-line-tool, dotnet-core
Pidgin
C#'s fastest parser combinator library
Stars: ✭ 469 (-2.49%)
Mutual labels:  dotnet-core
Nukeeper
Automagically update nuget packages in .NET projects
Stars: ✭ 437 (-9.15%)
Mutual labels:  dotnet-core
Magento Nginx Config
Default Nginx config for Magento
Stars: ✭ 462 (-3.95%)
Mutual labels:  webserver
Vim Ide
VIM configured as powerful IDE (Integrated Development Environment)
Stars: ✭ 441 (-8.32%)
Mutual labels:  command-line-tool
Polaris
A cross-platform, minimalist web framework for PowerShell
Stars: ✭ 464 (-3.53%)
Mutual labels:  webserver
Opentabletdriver
Open source, cross-platform, user-mode tablet driver
Stars: ✭ 424 (-11.85%)
Mutual labels:  dotnet-core
K2tf
Kubernetes YAML to Terraform HCL converter
Stars: ✭ 477 (-0.83%)
Mutual labels:  command-line-tool
Xcov
Nice code coverage reporting without hassle
Stars: ✭ 467 (-2.91%)
Mutual labels:  command-line-tool
Dateutils
nifty command line date and time utilities; fast date calculations and conversion in the shell
Stars: ✭ 458 (-4.78%)
Mutual labels:  command-line-tool
Git Big Picture
Git — the big picture
Stars: ✭ 456 (-5.2%)
Mutual labels:  command-line-tool
Pi Timolo
Raspberry PI-TIMOLO ( PI-TImelapse, MOtion, LOwLight ) uses RPI picamera and OpenCV for Remote Headless Security Monitoring using Motion Tracking, Rclone Auto Sync files with remote storage services. Auto Twilight Transitions and Low Light Camera Settings. Panoramic images using PanTiltHat and More. This project is featured on GitHub Awesome software.
Stars: ✭ 441 (-8.32%)
Mutual labels:  webserver
Jsonapidotnetcore
JSON:API Framework for ASP.NET Core
Stars: ✭ 465 (-3.33%)
Mutual labels:  dotnet-core
Embassy
Super lightweight async HTTP server library in pure Swift runs in iOS / MacOS / Linux
Stars: ✭ 440 (-8.52%)
Mutual labels:  webserver
Telegraph
Secure Web Server for iOS, tvOS and macOS
Stars: ✭ 474 (-1.46%)
Mutual labels:  webserver
Ascii Art
A Node.js library for ansi codes, figlet fonts, ascii art and other ASCII graphics
Stars: ✭ 437 (-9.15%)
Mutual labels:  command-line-tool
Drive Cli
A command line interface for accessing google drive
Stars: ✭ 449 (-6.65%)
Mutual labels:  command-line-tool
Smartcode
SmartCode = IDataSource -> IBuildTask -> IOutput => Build Everything!!!
Stars: ✭ 464 (-3.53%)
Mutual labels:  dotnet-core
Netfabric.hyperlinq
High performance LINQ implementation with minimal heap allocations. Supports enumerables, async enumerables, arrays and Span<T>.
Stars: ✭ 479 (-0.42%)
Mutual labels:  dotnet-core
Wsgidav
A generic and extendable WebDAV server based on WSGI
Stars: ✭ 476 (-1.04%)
Mutual labels:  webserver

dotnet-serve

Build Status Code Coverage NuGet NuGet Downloads

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 Core or .NET 5+ 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

Usage

Usage: dotnet serve [options]

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.
  -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 (requires .NET Core 3+)
  -c|--cors                            Enable CORS (It will enable CORS for all origin and all methods)
  --save-options                       Save specified options to .netconfig for subsequent runs.
  -?|--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 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

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].