2012-02-12 09:38:52 -05:00
|
|
|
# Ring-Server
|
2012-02-07 17:35:55 -05:00
|
|
|
|
2012-02-12 09:38:52 -05:00
|
|
|
A library for starting a web server to serve a [Ring][1] handler with
|
|
|
|
sensible default options and environment variable overrides.
|
2012-02-07 17:35:55 -05:00
|
|
|
|
2013-11-03 01:16:54 -05:00
|
|
|
[1]: https://github.com/ring-clojure/ring
|
2012-02-07 17:35:55 -05:00
|
|
|
|
2012-02-12 09:38:52 -05:00
|
|
|
## Features
|
|
|
|
|
|
|
|
When starting in development mode (i.e. `LEIN_NO_DEV` is not set):
|
|
|
|
|
|
|
|
* The server finds a free port to start on
|
|
|
|
* It automatically reloads changed files
|
|
|
|
* It renders exceptions and their stacktraces in HTML
|
|
|
|
* A web browser is automatically opened to the started server
|
|
|
|
|
|
|
|
In production:
|
|
|
|
|
|
|
|
* You can specify the port via the `PORT` environment variable
|
|
|
|
* You can add hooks to run on startup and shutdown.
|
|
|
|
|
|
|
|
## Install
|
|
|
|
|
|
|
|
Add the following dependency to your `project.clj` file:
|
|
|
|
|
2013-08-30 06:23:15 -04:00
|
|
|
[ring-server "0.3.0"]
|
2012-02-12 09:38:52 -05:00
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
|
|
Simple usage:
|
|
|
|
|
|
|
|
```clojure
|
|
|
|
(use 'ring.server.standalone)
|
|
|
|
(serve your-handler)
|
|
|
|
```
|
|
|
|
|
|
|
|
You can also specify a map of options:
|
|
|
|
|
|
|
|
```clojure
|
|
|
|
(serve your-handler {:port 4040})
|
|
|
|
```
|
|
|
|
|
|
|
|
The following options are supported:
|
|
|
|
|
|
|
|
* `:port` - The port to start the server on, overrides `$PORT`
|
|
|
|
|
|
|
|
* `:join?` - Whether to wait until the server stops (default true)
|
|
|
|
|
|
|
|
* `:init` - A function executed when the server starts
|
|
|
|
|
|
|
|
* `:destroy` - A function executed when the server stops
|
|
|
|
|
|
|
|
* `:open-browser?` -
|
|
|
|
True if you want a browser to be opened to the server. Defaults to
|
|
|
|
true in development mode, false in production mode.
|
|
|
|
|
2013-01-28 06:41:54 -05:00
|
|
|
* `:browser-uri` -
|
|
|
|
A path to append to the target URL if opening a browser (default
|
|
|
|
none). The full URI will be constructed like:
|
|
|
|
`http://{host}:{port}{browser-uri}`
|
|
|
|
|
2013-05-24 10:00:36 -04:00
|
|
|
* `:stacktraces?` -
|
2012-05-24 06:21:38 -04:00
|
|
|
True if you want a stacktrace to be displayed in the browser when
|
|
|
|
an exception is raised. Default to true in development, false in
|
|
|
|
production.
|
|
|
|
|
|
|
|
* `:auto-reload?` -
|
|
|
|
True if you want your source files to be automatically reloaded
|
|
|
|
when they are modified. Defaults to true in development, false in
|
|
|
|
production.
|
2013-02-18 07:25:03 -05:00
|
|
|
|
|
|
|
* `:reload-paths` -
|
|
|
|
A seq of source paths to reload. Defaults to [\"src\"].
|
|
|
|
Only relevant if :auto-reload? is true.
|
2012-05-24 06:21:38 -04:00
|
|
|
|
|
|
|
* `:auto-refresh?` -
|
|
|
|
True if you want your browser to automatically refresh when source
|
|
|
|
files are changed. Defaults to false.
|
2012-02-07 17:35:55 -05:00
|
|
|
|
|
|
|
## License
|
|
|
|
|
2012-02-12 09:38:52 -05:00
|
|
|
Copyright (C) 2012 James Reeves
|
2012-02-07 17:35:55 -05:00
|
|
|
|
|
|
|
Distributed under the Eclipse Public License, the same as Clojure.
|