Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nameoverflow/eliter
Build node.js server elegantly
https://github.com/nameoverflow/eliter
Last synced: 3 months ago
JSON representation
Build node.js server elegantly
- Host: GitHub
- URL: https://github.com/nameoverflow/eliter
- Owner: nameoverflow
- Created: 2016-02-22T04:17:11.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-05-17T06:06:34.000Z (over 8 years ago)
- Last Synced: 2024-10-06T20:34:27.313Z (3 months ago)
- Language: JavaScript
- Homepage:
- Size: 823 KB
- Stars: 19
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Eliter
[![Build Status](https://travis-ci.org/nameoverflow/eliter.svg?branch=master)](https://travis-ci.org/nameoverflow/eliter)
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)Eliter is a tiny node.js web server framework, providing generator-based async APIs.
## Quick Start
### Install
```
npm install eliter --save
```### Hello World
```javascript
const Eliter = require('eliter')
let app = new Eliter()
app.route('/').get(function* () {
this.send('text', 'hello eliter!') // `this` there is an instance of class Connection
})// `::` stands for a URL param
app.route('/do/::', function* (act, child) {
this.act = act
yield* child // the last param is handler of child route
}).route('/::').get(function* (name) {
this.send('text', `${this.act} ${name}`)
})// /do/hello/world => "hello world"
app.start(4000)
```
## What it looks like
### Generator-based Async
```javascript
const app = new Eliter()
app.route('/').get(function *() {
const data = yield getFromModel()
this.send('json', data)
})
```### Nested Router and Middleware
```javascript
const app = new Eliter()const admin = app.route('/admin', function *(child) {
const { data: { auth }} = yield this.session()
if (auth) {
yield* child
} else {
this.send({ status: 302, headers: { Location: '/login' }})
}
})const profile = admin.route('/profile').get(function* () {
const data = yield getFromModel()
this.send('html', `Hello, ${data.username}
`)
})
```### Pluginable
```javascript
const app = new Eliter()const checkAuth = conn => conn.checkAuth = function* () {
const { data: { auth }} = yield this.session()
return !!auth
}app.with(checkAuth)
const admin = app.route('/admin', function *(child) {
if (yield* this.checkAuth()) {
yield* child
} else {
this.send({ status: 302, headers: { Location: '/login' }})
}
})
```## Docs - FIXME
Check [gh-pages](http://nameoverflow.github.io/eliter/)