Coder Social home page Coder Social logo

markchipman / dotnet-serve Goto Github PK

View Code? Open in Web Editor NEW

This project forked from natemcmaster/dotnet-serve

0.0 1.0 0.0 205 KB

Simple command-line HTTPS server for the .NET Core CLI

Home Page: https://www.nuget.org/packages/dotnet-serve/

License: Apache License 2.0

PowerShell 3.23% C# 96.09% Shell 0.52% JavaScript 0.03% HTML 0.12%

dotnet-serve's Introduction

dotnet-serve

Build Status

NuGet

A simple command-line HTTP server.

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

Get started

Download .NET Core 2.1 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 [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+)
  -?|--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

dotnet-serve's People

Contributors

natemcmaster avatar dependabot-preview[bot] avatar andrewlock avatar daveaglick avatar gldraphael avatar sonicgd avatar tarmil avatar pranavkm avatar shanselman avatar ctyar avatar ysmoradi avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.