apiwee
Version:
basic api key managament
80 lines (58 loc) • 2.46 kB
Markdown
A fast and lightweight solution for quickly adding api keys to an Express application
```bash
$ npm install apiwee
```
```js
var express = require('express');
var app = express();
var apiweeConfig = {
username: 'username', // required
password: 'password', // required
publicPaths: ['GET:/', 'GET:/health'], // optional
file: __dirname + '/../myNewFileLocation' // optional, otherwise stored in node_modules/apiwee
}
var apiwee = require('apiwee')(express, app,apiweeConfig);
app.use(apiwee);
app.listen(3000);
```
Apiwee is added to the Express middleware functionality, where it validates from a local file (slower than memory but can be updated dynamically).
then navigate to {yourDomain}:{yourPort}/apiwee/admin and login with the credentials provided in the instantiation
this will take you to the configurations page where you can define the keys and the routes. You can delete keys, add new ones, edit the key field, drag routes to the api key, and disable keys.
once your api keys are defined use them by using the header field `x-api-key`
username and password are shown hard-coded in the config but use your best judgement on how to pass them into the instantiation.
ensure that each aws instance has permissions for running the aws cli command _describe-instances_
it also requires you to use the tags `Environment` and `Name` for the groups
below are the required fields for setting up the api keys on all instances in your aws asg group
```js
var apiweeConfig = {
username: 'username',
password: 'password',
awsRegion: 'us-east-1',
awsEnvironment: 'development',
awsInstanceName: 'myApp',
protocol: 'http/https',
port: 3000
}
var apiwee = require('apiwee')(express,app,apiweeConfig);
```
below is the required config for scaling your api keys across instances using their addresses
_Include *all* ips, including the address it is running on_
```js
var apiweeConfig = {
username: 'username',
password: 'password',
ips: ['1.1.1.1', '1.1.1.2', '1.1.1.3'],
protocol: 'http/https',
port: 3000
}
var apiwee = require('apiwee')(express,app,apiweeConfig);
```

