An open API service indexing awesome lists of open source software.

https://github.com/co2-git/prontojs

Web server based on Express
https://github.com/co2-git/prontojs

Last synced: about 1 year ago
JSON representation

Web server based on Express

Awesome Lists containing this project

README

          

prontojs !`very-alpha`
========

888 d8b
888 Y8P
888
88888b. 888d888 .d88b. 88888b. 888888 .d88b. 8888 .d8888b
888 "88b 888P" d88""88b 888 "88b 888 d88""88b "888 88K
888 888 888 888 888 888 888 888 888 888 888 "Y8888b.
888 d88P 888 Y88..88P 888 888 Y88b. Y88..88P 888 X88
88888P" 888 "Y88P" 888 888 "Y888 "Y88P" 888 88888P'
888 888
888 d88P
888 888P"

.dS$:::::.....
.d$$$$$::::::::::::...
d$$$$$$$:::::::::::::::::::..
d$$$$$$$::::::::::::::::::::::::.
d$$$$$$::::::::::::::::::::::::::::.
.d$$$$$$:::::::::::::::::::::::::::::::.
.d$$$$$$::::::::::::::::::::::::::::::::::
.d$$$$$:::::::::::::::::::::::::::::::::::::.
.d$$$$$$$$$$::::::::::::::::::::::::::::::::::.
.d$$$$$$$$$$$$$$$$$$$$$$::::::::::::::::::::::::
.d$$$$$$$$$$$$$$$$$$$$$$$$$$$$:::::::::::::::::::
d$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$:::::::::::
.:::::::::. .$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$:::::::
`:::::::::::::. $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$::::
`::::::::::::::::'::$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$::
:::::::::::::::::::::::.$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$:
::$$$:$$$$$$$$$$$$$$$$$$$Ss.::::::::*4$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$Ss:::::::::*4$$$$$$$$$$$$$$$$$$$$$$$
`q$$$$$$$$$$$$$$$$$$$$$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$$$$$$$$$$$$$$$$$$$$$$$:::.'' !$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$.'' .$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$ """""""""""; .$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$. MMMMMMMMMMM; .$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$. MMMMMMMMMMMM; !$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$S. MMMMMMMMM' ; .$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$. MMMMMMMM' ; .$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$. MMMMMMM' ; .$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$. MMMMM' ; .$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$MMMMMMM ; .$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$MMMMMMMMz. ; .$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$MMMMMMMMMz ;.$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$MMMMMMMMMM. ;.$$$$$$$$$$$$$$$$$$$$$$$$

`prontojs` is a Node module that creates HTTP(S) daemons (*Web Servers*). `prontojs` creates web servers that focus on serving resources. You tell `prontojs` which files you want to share with the Web, under which conditions and how to open them.

# Install

```bash
npm install prontojs
```

# Usage

```js
var pronto = require('prontojs');
var when = pronto.when;

// Create a new web server serving images
pronto().share('images/');

// Create a new web server as API
pronto().share('lib/', {
opener: 'js/callback',
args: [pronto.ifThenElse(pronto.method.is.post.or.put, pronto.payload, pronto.query)],
as: 'json' });
```

# Some user cases

## Want to start a new HTTP server?

```js
pronto();
/**
GET /

HTTP 404 Not Found
...
*/
```

## Want to share a folder with the web?

```
/images
/birthday.jpg
```

```js
pronto().share('images/'); // Now all the files in images/ folder are served
/**
GET /birthday.jpg

HTTP 200 OK
Content-Type: image/jpg
...
*/
```

## Want to restrict who you share it with?

```js
pronto().share('images/',

when.is.user.
and.
is.visiting.from('Russia').
and.
is.using.an.iPhone(4).
and.
method.is.GET.
and.
except.when.
it.is.the.week.end);
```

## Want to share your Jade files rendered into HTML?

```
/views
/home.jade
```

```yaml
//- home.jade
h1 Hello
```

```js
// pronto.js

pronto().share('views');
/**
GET /home.jade

HTTP 200 OK
Content-Type: text/html; charset=utf-8

Hello


*/
```

## Want to execute JS functions via HTTP?

```js
// foo.js

module.exports = function () { return 'hello'; };

// pronto.js

pronto().share('foo.js', { as: 'text', opener: 'js/function' } );
/**
GET /foo.js

HTTP 200 OK
Content-Type: text/plain; charset=utf-8

hello
*/
```

## Want to execute JS callbacks via HTTP?

```js
// foo.js

module.exports = function (cb) { cb(null, 'hello') };

// pronto.js

pronto().share('foo.js', { as: 'text', opener: 'js/callback' } );
/**
GET /foo.js

HTTP 200 OK
Content-Type: text/plain; charset=utf-8

hello
*/
```

## Want to execute your JS promises via HTTP?

```js
// foo.js

module.exports = function () { return 'hello'; }

// pronto.js

pronto().share('foo.js', { as: 'text', opener: 'js/promise' } );
/**
GET /foo.js

HTTP 200 OK
Content-Type: text/plain; charset=utf-8

hello
*/
```

## Want to execute your JS emitters via HTTP?

```js
// foo.js

function Emitter () {
process.nextTick(function () {
this.emit('OK', 'hello');
}.bind(this));
}

require('util').inherits(Emitter, require('events').EventEmiiter);

module.exports = Emitter;

// pronto.js

pronto().share('foo.js', { opener: 'js/emitter', as: { 'text': { on: 'OK' } } });
/**
GET /foo.js

HTTP 200 OK
Content-Type: text/plain; charset=utf-8

hello
*/
```

## Want to execute your JS routes via HTTP?

```js
// foo.js

module.exports = function (req, res, next) { res.send('hello'); }

// pronto.js

pronto().share('foo.js', { as: 'text', opener: 'js/route' } );
/**
GET /foo.js

HTTP 200 OK
Content-Type: text/plain; charset=utf-8

hello
*/
```

===

# Open

`prontojs` puts the focus on serving files

```js
pronto().open ( 'index.html' );
/**
GET /index.html

HTTP 200 OK
Content-Type: text/html; charset=utf-8"

...
*/

pronto().open ( 'image.png' );
/**
GET /image.png

HTTP 200 OK
Content-Type: image/png

...
*/
```

## Open as

```js
pronto().open ( 'index.html', { as: 'txt' } );
/**
GET /index.html

HTTP 200 OK
Content-Type: text/plain; charset=utf-8

...
*/
```

We have built-in handlers for the more popular template engines:

```haml
//- index.jade

h1 Hello
```

```js
// pronto.js

pronto().open ( 'index.jade' );
/**
GET /index.jade

HTTP 200 OK
Content-Type: text/html; charset=utf-8

Hello


*/
```

We have built-in handlers for the more popular preprocessors, for example SASS:

```css
/* index.scss */

$color: #999;

body { h1 { color: $color } }
```

```js
// pronto.js

pronto().open ( 'index.scss' );
/**
GET /index.scss

HTTP 200 OK
Content-Type: text/css; charset=utf-8

body h1 { color: #999 }
*/
```

We have built-in handlers for the more popular interpreters:

```php
=PHP_VERSION
```

```js
pronto().open ( 'index.php' );
/**
GET /index.php

HTTP 200 OK
Content-Type: text/html; charset=utf-8

3.2.1
*/
```

## Custom openers

You can build your custom openers:

```
index.txt
===
Hello John!
```

```js
function countOccurencies () {

}

pronto().open ( 'index.css', { with: function (stream) { /* your opener here */ } } );
```

## Custom types

You can build your custom types:

```js
pronto().type ( 'abc', function () { /* your opener here */ } } );
```

## Open directories

Opening a directory automatically opens all the files in this directory. Imagine the following directory:

```
app/
index.html
```

To serve this directory:

```js
pronto().open ( 'app/' );
```

```bash
curl http://localhost:3000/index.html # gets app/index.html
```

## Indexes

The example above could have been shorted to:

```bash
curl http://localhost:3000/ # gets app/index.html
```

When the route points to a directory, it will get the file matching globbing pattern `index.*`. If more than one file is found, first in the list is used.

```bash
curl http://localhost:3000/js # gets app/js/index.js
```

You can turn off indexes like this;

```js
pronto.open ( { index: false } )
```

Or you can specify your own index:

```js
pronto.open ( { index: 'README.md' } );
```

This is the one we use as default:

```js
pronto.open ( { index: 'index.*' } );
```

# Exec

As seen before, some file extensions are automatically opened as executable:

```js
pronto.open( 'index.py' ); // execute this file with Python
```

JS files are opened as static JS files:

```js
pronto.open( 'index.js' );
/**
GET /index.js

HTTP 200 OK
Content-Type: text/javascript; charset=utf-8
```

If you want to open a JS file with Node or IO, do like this:

```js
// morning.js

module.exports = function () {
return "Good morning";
};

pronto.exec( 'morning.js', when.time.is( 'AM' ) );
/**
GET /index.js

HTTP 200 OK
Content-Type: text/javascript; charset=utf-8
```

You have flexible support

# Passport

We have passport.js for auth

```js
pronto().passport({ strategies: ['local', 'facebook', 'twitter', 'google+', 'linkedin', 'github'] });
```

## Local strategy

```
POST /sign/in email=john@doe.com&password=1234

HTTP 200 OK
Content-Type: application/json; charset=utf-8
Cookie: ...

{ "welcome": User }
```