Skip to content

Commit

Permalink
Merge pull request #5 from Potentii/v2.2.0
Browse files Browse the repository at this point in the history
v2.2.0
  • Loading branch information
Potentii authored Jul 30, 2017
2 parents 1f349a3 + 7b586f5 commit 481a864
Show file tree
Hide file tree
Showing 27 changed files with 1,738 additions and 596 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.rnd
/test/mock/https/*

# Logs
logs
*.log
Expand Down
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.tern-project
.gitattributes
.rnd
/test
20 changes: 20 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
language: node_js

node_js:
- "8"

dist: trusty

cache:
directories:
- node_modules

before_install:
- mkdir -p ./test/mock/https
- openssl req -subj "/C=BR/ST=São Paulo/L=Campinas/O=Guilherme/CN=Guilherme" -newkey rsa:2048 -days 365 -nodes -x509 -keyout ./test/mock/https/key.key -out ./test/mock/https/cert.crt
- openssl pkcs12 -export -out ./test/mock/https/pfx.pfx -inkey ./test/mock/https/key.key -in ./test/mock/https/cert.crt -password pass:123456789
- touch ./test/mock/https/pass.txt
- printf "123456789" > ./test/mock/https/pass.txt

notifications:
email: false
35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ It makes the process of setting up a web server less verbose, by wrapping an `Ex
- [Other examples](#other-examples)
- [Website](#website)
- [Web service](#web-service)
- [HTTPS](#https)
- [CORS](#cors)
- [Body parsing](#body-parsing)
- [Testing](#testing)
Expand Down Expand Up @@ -115,7 +116,7 @@ _**See:**_

- [_StaticConfigurator_](docs/static-configurator.md)
- [*StaticConfigurator.prototype.add(route, resource\_path)*](docs/static-configurator.md#staticconfiguratorprototypeaddroute-resource_path)
- [_StaticConfigurator.prototype.index(file)_](docs/static-configurator.md#staticconfiguratorprototypeindexfile)
- [_StaticConfigurator.prototype.index(file)_](docs/static-configurator.md#staticconfiguratorprototypeindexfile-options)

***

Expand Down Expand Up @@ -204,6 +205,38 @@ _**See:**_

<br>

### HTTPS

It's simple to configure an HTTPS server using a **key** and **certificate**:

```javascript
server
.https({
key: './my-key.key',
cert: './my-cert.crt'
}, true)
// ...
```

or using a **PFX** file:

```javascript
server
.https({
pfx: './my-pfx.pfx',
passphrase: './my-pass.txt'
}, true)
// ...
```

_**See:**_

- [*Configurator.prototype.https(options, is\_file)*](docs/configurator.md#configuratorprototypehttpsoptions-is_file)

***

<br>

### CORS

The [`advanced configurator`](docs/advanced-api-configurator.md) helps you to setup CORS responses correctly:
Expand Down
47 changes: 47 additions & 0 deletions docs/configurator.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,53 @@ server

<br>

### Configurator.prototype.https(options, is\_file)

Switches the server to use HTTPS.

_**Note:** calling this method will make the default server port to be `443` instead of `80`._

#### Parameters

- `options` _object_ \- The HTTPS options object
- `cert` _string_ \- The HTTPS certificate
- `key` _string_ \- The HTTPS key
- `pfx` _string_ \- The HTTPS pfx
- `passphrase` _string_ \- The HTTPS pfx password
- `is_file` _boolean_ \- Whether the options values are filenames, and should be retrieved from disk

#### Returns

[_Configurator_](#) \- This same configurator (for method chaining)

#### Examples

Using **key** and **certificate** files:

```javascript
server
.https({
key: './my-key.key',
cert: './my-cert.crt'
}, true)
// ...
```

Using a **PFX** file:

```javascript
server
.https({
pfx: './my-pfx.pfx',
passphrase: './my-pass.txt'
}, true)
// ...
```

***

<br>

### Configurator.prototype.on(event, listener)

Registers a handler for a given event.
Expand Down
2 changes: 1 addition & 1 deletion docs/static-configurator.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let static_configurator = server.static;

_string_ \- The index file path (absolute)

_**Note:** readonly, use the_ [_`index()`_](#staticconfiguratorprototypeindexfile) _method to assign a value._
_**Note:** readonly, use the_ [_`index()`_](#staticconfiguratorprototypeindexfile-options) _method to assign a value._

***

Expand Down
7 changes: 4 additions & 3 deletions libs/advanced-api-configurator.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// *Requiring the needed modules:
const { PARSERS } = require('./parsers.js');
const { PARSERS } = require('./utils/parsers');
const ParserData = require('./types/parser-data');



Expand Down Expand Up @@ -233,13 +234,13 @@ module.exports = class AdvancedAPIConfigurator{
/**
* The parsers list
* @readonly
* @return {Array} An array containing { type, options } objects
* @return {Array<ParserData>} An array containing ParserData objects
*/
get parsers(){
// *Starting the list:
let parsers = [];
// *Filling the list with the map's content:
this._parsers.forEach((v, k) => parsers.push({type: k, options: v}));
this._parsers.forEach((options, type) => parsers.push(new ParserData(type, options)));
// *Returning the list:
return parsers;
}
Expand Down
7 changes: 4 additions & 3 deletions libs/api-configurator.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// *Requiring the needed modules:
const { METHODS, isMethodSupported } = require('./methods.js');
const APIResource = require('./api-resource.js');
const AdvancedAPIConfigurator = require('./advanced-api-configurator.js');
const { METHODS, isMethodSupported } = require('./utils/methods');
const APIResource = require('./types/api-resource');
const AdvancedAPIConfigurator = require('./advanced-api-configurator');



/**
Expand Down
Loading

0 comments on commit 481a864

Please sign in to comment.