Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sinedied/nano-gateway
:zap: Lightweight API gateway for home-scale projects
https://github.com/sinedied/nano-gateway
api express gateway hacktoberfest https nano secure yaml
Last synced: 4 months ago
JSON representation
:zap: Lightweight API gateway for home-scale projects
- Host: GitHub
- URL: https://github.com/sinedied/nano-gateway
- Owner: sinedied
- License: mit
- Created: 2017-12-24T10:08:21.000Z (about 7 years ago)
- Default Branch: main
- Last Pushed: 2022-12-07T07:56:45.000Z (about 2 years ago)
- Last Synced: 2024-10-04T13:26:45.069Z (5 months ago)
- Topics: api, express, gateway, hacktoberfest, https, nano, secure, yaml
- Language: JavaScript
- Homepage:
- Size: 792 KB
- Stars: 19
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# nano-gateway
[](https://www.npmjs.com/package/nano-gateway)
[](https://github.com/sinedied/nano-gateway/actions)

[](https://hub.docker.com/r/sinedied/nano-gateway/)
[](https://github.com/sindresorhus/xo)
[](LICENSE)
> Lightweight API gateway for home-scale projects.
**Features:**
- Single-file YAML configuration
- HTTPS support
- Secure endpoints with API key
- URL rewriting
- Less than [60 LOC](index.js) :smile:## Installation
```bash
npm install -g nano-gateway
```## Usage
```sh
Usage: nanog [--config file.yml] [--keygen]
```Use the `nanog` command to start the gateway.
By default, it will use the `config.yml` configuration in the current working directory, but any file can be specified
using either the `NANO_GATEWAY_CONFIG` environment variable or the `--config` option.The `--keygen` will generate a suitable API key to use in your configuration.
## Configuration
Here is an [example config.yml](config.yml) configuration:
```yaml
http: # optional, enable HTTP gateway
port: 8080 # optional, specify port for HTTP (default is 8080)
https: # optional, enable HTTPS gateway
cert: 'cert.pem' # required, certificate path
key: 'privkey.pem' # required, private key path
ca: 'chain.pem' # optional, override trusted CA certificates
port: 8443 # optional, specify port for HTTPS (default is 8443)
auth: true # optional, enable API key authorization by default for all services
apiKey: '123456' # required if auth is enabled, use nanog --keygen to generate a new key
services: # required, define here the services to proxify
ip: # required, service name
path: '/ip' # required, endpoint(s) (use Express route syntax, see npmjs.com/path-to-regexp)
url: 'https://httpbin.org' # required, target url for
auth: false # optional, authorization can be set or overriden by service
quote: # another service, add as many as you need
path: '/jokes/*' # matches any routes under /jokes/
rewrite: '/jokes/random' # optional, rewrite URL (for syntax, see npmjs.com/express-urlrewrite)
url: 'https://api.chucknorris.io'
```### API key
Endpoints secured by API key can be consumed either by using an `apiKey` query parameter:
```sh
curl https://gateway.com/endpoint?apiKey=
```
or by using an `Authorization` header:
```sh
curl -H "Authorization: " https://gateway.com/endpoint
```> Note: It is **strongly** recommended to use only HTTPS with API keys, otherwise your credentials will circulate in
> clear over the network and may be intercepted.### HTTPS
To enable HTTPS you need a valid SSL certificate.
Free [LetsEncrypt](https://letsencrypt.org) certificates can be obtained using [certbot](https://certbot.eff.org).
For testing purposes, you can also generate a self-signed certificate using this command:
```sh
openssl req -nodes -new -x509 -keyout privkey.pem -out cert.pem
```After you have your certificate, use it in your configuration like this:
```yaml
https:
cert: 'cert.pem'
key: 'privkey.pem'
ca: 'chain.pem' # optional, override trusted CA certificates
```## Running on Docker
A minimal [Docker image](https://hub.docker.com/r/sinedied/nano-gateway/) based on `node:alpine` is also available
for deployment.You just need to map a folder with a `config.yml` file in it to the `/config` volume:
```
docker pull sinedied/nano-gateway
docker run --d -v :/config -p 8443:8443 --name nano-gateway sinedied/nano-gateway
```