https://github.com/aleclarson/slush
Basic HTTP server for NodeJS
https://github.com/aleclarson/slush
nodejs nodejs-framework nodejs-server
Last synced: about 1 month ago
JSON representation
Basic HTTP server for NodeJS
- Host: GitHub
- URL: https://github.com/aleclarson/slush
- Owner: aleclarson
- License: mit
- Created: 2017-03-22T03:39:13.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2018-12-22T16:43:08.000Z (over 7 years ago)
- Last Synced: 2025-06-14T15:04:50.320Z (12 months ago)
- Topics: nodejs, nodejs-framework, nodejs-server
- Language: JavaScript
- Homepage:
- Size: 97.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# slush v3.2.1 
Lightweight replacement to `express`.
```coffee
slush = require "slush"
app = slush()
app.ready ->
console.log "Listening at http://localhost:" + app.port
```
### Options
- **sock: String?** Listen on a socket path
- **port: Number?** If undefined, default to `process.env.PORT`, or `443` (if HTTPS), or `8000` (if HTTP)
- **secure: Boolean?** If true, an HTTPS server is created with `ssl.key` and `ssl.crt` from the project root
- **maxHeaders: Number?** Limit the number of headers (defaults to 50)
- **timeout: Number?** The timeout (in ms) before a request sends a 408 response
- **onError: Function?** Send a custom response when your server throws an unexpected error
- **onUnhandled: Function?** Send a custom response when a request goes unhandled
### Request handling
The `slush` server uses a pipeline of request handlers (called "pipes").
```coffee
app.pipe (req, res) ->
# Handle the request in here.
# Calls to `pipe` can be chained.
```
The return value of each pipe is used to determine the server's next action.
Return `undefined` or `null` to skip the rest of the current pipe.
Return a `Number` literal to set the status code for an empty response.
Return an `Error` instance for invalid requests.
Return a `Promise` instance for asynchronous requests.
The resolved value is treated the same as synchronous return values.
The server will visit each pipe in the pipeline until `res.send` is called.
If that never happens, the server responds with "404 Not Found".
If an `Error` instance is thrown while inside a pipe, the server responds with "500 Internal Error".
### Express middleware
Support for `express` middleware is included.
```coffee
app.use middleware
```
### The `drain` method
Use the `drain()` method for running code after the response is sent.
```coffee
app.drain (req, res) ->
# The response has been sent.
```
### Server events
- `request: (req, res)` A request was received
- `response: (req, res)` A response has finished
- `requestError: (error)` The request handler caught an error (not emitted when `options.onError` is defined)
- `error: ()` A server error occurred [(see here)](https://nodejs.org/api/net.html#net_event_error)
- `close: ()` The server has closed, all connections have ended [(see here)](https://nodejs.org/api/net.html#net_event_close)