Skip to content
/ serve Public

Serve is escript to quickly start an HTTP server, with directory index.

License

Notifications You must be signed in to change notification settings

quexpl/serve

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Serve

Actions Status Hex pm Hexdocs badge

Serve is escript to quickly start an HTTP server, similar to quick-start solutions available in other languages:

$ php -S localhost:8080
$ ruby -run -e httpd . -p 8080
$ python3 -m http.server 8080

With Serve, you can quickly start an HTTP server:

$ serve /var/www/html
[info] Serving /var/www/html with Cowboy 2.13.0 at http://127.0.0.1:4444

Installation

To install from Hex, run:

$ mix escript.install hex serve

To build and install it locally run:

$ mix install

it's a alias for:

$ mix do deps.get, escript.build, escript.install

Note: For convenience, consider adding ~/.mix/escripts directory to your $PATH environment variable. If you are using asdf Whenever you install a new escript with mix escript.install you need to asdf reshim elixir in order to create shims for it.

If you want to uninstall Serve simply run:

$ mix escript.uninstall serve

Options

Comand line options

You can pass options directly to serve

  • -p, --port - Specify the port to listen on (default: 4444).
  • -o, --open - Open the browser automatically.
  • -n, --no-index - Disable directory listing.
  • -v, --version - Shows Serve version.
  • -h, --help - Shows Serve usage information.
$ serve --port 3000

Environment variables

Serve also supports environment variables for all options. Simply use env with MIX_SERVE_ prefix.

$ MIX_SERVE_PORT=3000 serve

You can also add exports to yours profile file, for example:

export MIX_SERVE_PORT=8000
export MIX_SERVE_OPEN=true
export MIX_SERVE_NO_INDEX=true

Arguments

Serve accepts one argument: the directory to be served. If no directory is specified, the current working directory is used.

$ pwd
/var/www/html/my_website
$ serve
[info] Serving  /var/www/html/my_website with Cowboy 2.13.0 at http://localhost:4444
$ mix docs
Generating docs...
View "html" docs at "doc/index.html"
View "epub" docs at "doc/serve.epub"
$ serve s doc
[info] Serving  /home/quex/workspace/serve/doc with Cowboy 2.13.0 at http://localhost:4444

Features

  • dark mode
  • directory index

dark mode directory index not found

Security

Although Serve uses the robust Cowboy HTTP server, it is not intended to be a production-ready web server. It only supports the HTTP protocol and listens on the loopback interface.