Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: http-party/http-server
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 23727988ba0207ccfeb0b46ac68ed9661c5291c1
Choose a base ref
...
head repository: http-party/http-server
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 77243e7a824a85b2ae0773b7a05fa24d41db2ce5
Choose a head ref
Loading
Showing with 18,176 additions and 245 deletions.
  1. +16 −0 .github/ISSUE_TEMPLATE
  2. +19 −0 .github/PULL_REQUEST_TEMPLATE
  3. +31 −0 .github/workflows/node.js.yml
  4. +5 −2 .gitignore
  5. +0 −13 .travis.yml
  6. +1 −1 LICENSE
  7. +92 −19 README.md
  8. +13 −0 SECURITY.md
  9. +65 −22 bin/http-server
  10. +160 −0 doc/http-server.1
  11. +34 −0 lib/core/aliases.json
  12. +18 −0 lib/core/defaults.json
  13. +9 −0 lib/core/etag.js
  14. +447 −0 lib/core/index.js
  15. +203 −0 lib/core/opts.js
  16. +65 −0 lib/core/show-dir/icons.json
  17. +171 −0 lib/core/show-dir/index.js
  18. +21 −0 lib/core/show-dir/perms-to-string.js
  19. +30 −0 lib/core/show-dir/size-to-string.js
  20. +36 −0 lib/core/show-dir/sort-files.js
  21. +20 −0 lib/core/show-dir/styles.js
  22. +96 −0 lib/core/status-handlers.js
  23. +57 −12 lib/http-server.js
  24. +14,151 −0 package-lock.json
  25. +44 −18 package.json
  26. BIN public/img/turtle.png
  27. BIN screenshots/directory.png
  28. BIN screenshots/public.png
  29. BIN screenshots/start.png
  30. +231 −0 test/304.test.js
  31. +66 −0 test/accept-encoding.test.js
  32. +126 −0 test/cache.test.js
  33. +17 −0 test/check-headers.js
  34. +124 −0 test/cli.test.js
  35. +187 −0 test/compression.test.js
  36. +52 −0 test/content-type.test.js
  37. +72 −0 test/core-error.test.js
  38. +74 −0 test/core.test.js
  39. +31 −0 test/custom-content-type-file-secret.test.js
  40. +47 −0 test/custom-content-type-file.test.js
  41. +33 −0 test/custom-content-type.test.js
  42. +22 −0 test/default-default-ext.test.js
  43. +20 −0 test/enotdir.test.js
  44. +21 −0 test/escaping.test.js
  45. +74 −0 test/express-error.test.js
  46. +76 −0 test/express.test.js
  47. +15 −0 test/fixtures/common-cases-error.js
  48. +160 −0 test/fixtures/common-cases.js
  49. +3 −0 test/fixtures/custom_mime_type.types
  50. +1 −0 test/fixtures/root/compression/index.html
  51. +3 −0 test/fixtures/root/compression/index.html.br
  52. BIN test/fixtures/root/compression/index.html.gz
  53. +4 −0 test/fixtures/root/htmlButNot
  54. +86 −0 test/headers.test.js
  55. +0 −158 test/http-server-test.js
  56. +26 −0 test/illegal-access-date.test.js
  57. +286 −0 test/main.test.js
  58. +20 −0 test/malformed-dir.test.js
  59. +21 −0 test/malformed.test.js
  60. +46 −0 test/mime.test.js
  61. +64 −0 test/process-env-port.test.js
  62. +1 −0 test/public/404.html
  63. BIN test/public/404.html.gz
  64. +1 −0 test/public/a.txt
  65. +1 −0 test/public/another-subdir/scripts.js
  66. +1 −0 test/public/b.txt
  67. +1 −0 test/public/brotli/fake_ecstatic
  68. BIN test/public/brotli/fake_ecstatic.br
  69. +1 −0 test/public/brotli/index.html
  70. +3 −0 test/public/brotli/index.html.br
  71. BIN test/public/brotli/index.html.gz
  72. +1 −0 test/public/brotli/not_actually_brotli.br
  73. +1 −0 test/public/brotli/real_ecstatic
  74. +2 −0 test/public/brotli/real_ecstatic.br
  75. +1 −0 test/public/c.js
  76. +1 −0 test/public/compress/foo.js
  77. BIN test/public/compress/foo.js.gz
  78. +1 −0 test/public/compress/foo_2.js
  79. +1 −0 test/public/curimit@gmail.com (40%)/index.html
  80. +13 −0 test/public/custom_mime_type.opml
  81. +3 −0 test/public/custom_mime_type.types
  82. +1 −0 test/public/d.js
  83. +1 −0 test/public/e.js
  84. +1 −0 test/public/f_f
  85. +1 −0 test/public/gzip/fake_ecstatic
  86. 0 test/public/gzip/fake_ecstatic.gz
  87. +1 −0 test/public/gzip/index.html
  88. BIN test/public/gzip/index.html.gz
  89. +1 −0 test/public/gzip/real_ecstatic
  90. BIN test/public/gzip/real_ecstatic.gz
  91. +4 −0 test/public/show-dir$$href_encoding$$/aname+aplus.txt
  92. +1 −0 test/public/subdir/app.wasm
  93. +1 −0 test/public/subdir/e.html
  94. +1 −0 test/public/subdir/index.html
  95. +1 −0 test/public/subdir_with space/file_with space.html
  96. +1 −0 test/public/subdir_with space/index.html
  97. +1 −0 test/public/中文/檔案.html
  98. +131 −0 test/range.test.js
  99. +34 −0 test/showdir-href-encoding.test.js
  100. +55 −0 test/showdir-pathname-encoding.test.js
  101. +35 −0 test/showdir-search-encoding.test.js
  102. +34 −0 test/showdir-with-spaces.test.js
  103. +26 −0 test/trailing-slash.test.js
16 changes: 16 additions & 0 deletions .github/ISSUE_TEMPLATE
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
**Steps to reproduce the issue, if applicable. Include the actual command and output and/or stack trace.**

<!-- Paste the command here: -->

**What did you expect to happen?**

<!-- Paste the error and / or stack trace here: -->

**If the issue is a feature request, what is the motivation / use case for it?**

**Tell us about your environment**
- **exact http-server version:**
- **Node version:**
- **Platform:**

**Other information (related issues, suggestions for a fix, etc):**
19 changes: 19 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
**Please ensure that your pull request fulfills these requirements:**
- [ ] The pull request is being made against the `master` branch
- [ ] Tests for the changes have been added (for bug fixes / features)

**What is the purpose of this pull request? (bug fix, enhancement, new feature,...)**

<!--
Link to the issue this pull request fixes here, if applicable: "Fixes #xxx" or "Resolves #xxx"
-->

**What changes did you make?**

**Provide some example code that this change will affect, if applicable:**

<!-- Paste the example code here: -->

**Is there anything you'd like reviewers to focus on?**

**Please provide testing instructions, if applicable:**
31 changes: 31 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:
name: Test
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
node-version: [10.x, 12.x, 14.x, 16.x]
os: [ubuntu-latest, macOS-latest, windows-latest]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }} on ${{ matrix.os }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npx npm@7 ci
- run: npm test
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
node_modules/*
npm-debug.log
node_modules/
npm-debug.log*
.nyc_*/
.dir-locals.el
.DS_Store
13 changes: 0 additions & 13 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2011 Charlie Robbins, Marak Squires, and the Contributors.
Copyright (c) 2011-2021 Charlie Robbins, Marak Squires, Jade Michael Thornton and the Contributors.

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
111 changes: 92 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
[![build status](https://img.shields.io/travis/indexzero/http-server.svg?style=flat-square)](https://travis-ci.org/indexzero/http-server)
[![dependencies status](https://img.shields.io/david/indexzero/http-server.svg?style=flat-square)](https://david-dm.org/indexzero/http-server)
[![npm](https://img.shields.io/npm/v/http-server.svg?style=flat-square)](https://www.npmjs.com/package/http-server)
[![license](https://img.shields.io/github/license/indexzero/http-server.svg?style=flat-square)](https://github.com/indexzero/http-server)
![GitHub Workflow Status (master)](https://img.shields.io/github/workflow/status/http-party/http-server/Node.js%20CI/master?style=flat-square)
[![npm](https://img.shields.io/npm/v/http-server.svg?style=flat-square)](https://www.npmjs.com/package/http-server) [![homebrew](https://img.shields.io/homebrew/v/http-server?style=flat-square)](https://formulae.brew.sh/formula/http-server) ![GitHub milestone](https://img.shields.io/github/milestones/progress-percent/http-party/http-server/8?label=next%20release%20progress&style=flat-square) [![npm downloads](https://img.shields.io/npm/dm/http-server?color=blue&label=npm%20downloads&style=flat-square)](https://www.npmjs.com/package/http-server)
[![license](https://img.shields.io/github/license/http-party/http-server.svg?style=flat-square)](https://github.com/http-party/http-server)

# http-server: a command-line http server

`http-server` is a simple, zero-configuration command-line http server. It is powerful enough for production usage, but it's simple and hackable enough to be used for testing, local development, and learning.

![](https://github.com/nodeapps/http-server/raw/master/screenshots/public.png)
![Example of running http-server](https://github.com/http-party/http-server/raw/master/screenshots/public.png)

# Installing globally:
## Installation:

Installation via `npm`:
#### Globally via `npm`

npm install http-server -g
npm install --global http-server

This will install `http-server` globally so that it may be run from the command line.
This will install `http-server` globally so that it may be run from the command line anywhere.

#### Globally via Homebrew

brew install http-server

#### Running on-demand:

Using `npx` you can run the script without installing it first:

npx http-server [path] [options]
#### As a dependency in your `npm` package:

npm install http-server

## Usage:

@@ -25,42 +38,102 @@ This will install `http-server` globally so that it may be run from the command

*Now you can visit http://localhost:8080 to view your server*

**Note:** Caching is on by default. Add `-c-1` as an option to disable caching.

## Available Options:

`-p` Port to use (defaults to 8080)
`-p` or `--port` Port to use (defaults to 8080). Use `-p 0` to look for an open port, starting at 8080. It will also read from `process.env.PORT`.

`-a` Address to use (defaults to 0.0.0.0)

`-d` Show directory listings (defaults to 'True')
`-d` Show directory listings (defaults to `true`)

`-i` Display autoIndex (defaults to 'True')
`-i` Display autoIndex (defaults to `true`)

`-g` or `--gzip` When enabled (defaults to 'False') it will serve `./public/some-file.js.gz` in place of `./public/some-file.js` when a gzipped version of the file exists and the request accepts gzip encoding.
`-g` or `--gzip` When enabled (defaults to `false`) it will serve `./public/some-file.js.gz` in place of `./public/some-file.js` when a gzipped version of the file exists and the request accepts gzip encoding. If brotli is also enabled, it will try to serve brotli first.

`-e` or `--ext` Default file extension if none supplied (defaults to 'html')
`-b` or `--brotli` When enabled (defaults to `false`) it will serve `./public/some-file.js.br` in place of `./public/some-file.js` when a brotli compressed version of the file exists and the request accepts `br` encoding. If gzip is also enabled, it will try to serve brotli first.

`-e` or `--ext` Default file extension if none supplied (defaults to `html`)

`-s` or `--silent` Suppress log messages from output

`--cors` Enable CORS via the `Access-Control-Allow-Origin` header

`-o` Open browser window after starting the server
`-o [path]` Open browser window after starting the server. Optionally provide a URL path to open. e.g.: -o /other/dir/

`-c` Set cache time (in seconds) for cache-control max-age header, e.g. -c10 for 10 seconds (defaults to '3600'). To disable caching, use -c-1.
`-c` Set cache time (in seconds) for cache-control max-age header, e.g. `-c10` for 10 seconds (defaults to `3600`). To disable caching, use `-c-1`.

`-U` or `--utc` Use UTC time format in log messages.

`--log-ip` Enable logging of the client's IP address (default: `false`).

`-P` or `--proxy` Proxies all requests which can't be resolved locally to the given url. e.g.: -P http://someurl.com

`--username` Username for basic authentication [none]

`--password` Password for basic authentication [none]

`-S` or `--ssl` Enable https.

`-C` or `--cert` Path to ssl cert file (default: cert.pem).
`-C` or `--cert` Path to ssl cert file (default: `cert.pem`).

`-K` or `--key` Path to ssl key file (default: `key.pem`).

`-r` or `--robots` Provide a /robots.txt (whose content defaults to `User-agent: *\nDisallow: /`)

`-K` or `--key` Path to ssl key file (default: key.pem).
`--no-dotfiles` Do not show dotfiles

`-r` or `--robots` Provide a /robots.txt (whose content defaults to 'User-agent: *\nDisallow: /')
`--mimetypes` Path to a .types file for custom mimetype definition

`-h` or `--help` Print this list and exit.

`-v` or `--version` Print the version and exit.

## Magic Files

- `index.html` will be served as the default file to any directory requests.
- `404.html` will be served if a file is not found. This can be used for Single-Page App (SPA) hosting to serve the entry page.

## Catch-all redirect

To implement a catch-all redirect, use the index page itself as the proxy with:

```
http-server --proxy http://localhost:8080?
```

Note the `?` at the end of the proxy URL. Thanks to [@houston3](https://github.com/houston3) for this clever hack!

## TLS/SSL

First, you need to make sure that [openssl](https://github.com/openssl/openssl) is installed correctly, and you have `key.pem` and `cert.pem` files. You can generate them using this command:

``` sh
openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -keyout key.pem -out cert.pem
```

You will be prompted with a few questions after entering the command. Use `127.0.0.1` as value for `Common name` if you want to be able to install the certificate in your OS's root certificate store or browser so that it is trusted.

This generates a cert-key pair and it will be valid for 3650 days (about 10 years).

Then you need to run the server with `-S` for enabling SSL and `-C` for your certificate file.

``` sh
http-server -S -C cert.pem
```

This is what should be output if successful:

``` sh
Starting up http-server, serving ./ through https
Available on:
https:127.0.0.1:8080
https:192.168.1.101:8080
https:192.168.1.104:8080
Hit CTRL-C to stop the server
```

# Development

Checkout this repository locally, then:
13 changes: 13 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Security Policy

## Supported Versions

| Version | Supported |
|---------|------------------------|
| 0.13.x | Yes :white_check_mark: |
| 0.12.x | Security updates only |
| < 0.12 | No :x: |

## Reporting a Vulnerability

In general, vulnerabilities can be reported as an issue, pull requests are very welcome. If you'd like to report privately, please email jademichael+http-server@jmthornton.net.
Loading