koa-stacks
Combines koa-route
, koa-mount
, and koa-basic-auth
to provide a declarative way to create koa
instances with prewired routes and middleware with optional and highly-configurable basic HTTP authentication.
Install:
$ npm install --save koa-stacks
Example:
; ;; const port = processenvport || 9999; const test } = ; http;console;
Run the server:
$ node .dist/tests/index.js
Constructing 'test' stack
Adding 'get' route at '/test'
Adding 'get' route at '/parameterized/:param'
Adding protected 'get' route at '/protected'
HTTP server listing on port 9999
Now run:
$ curl by:password@localhost:9999/protected
authorized!
$ curl localhost:9999/protected
Unauthorized
$ curl localhost:9999/parameterized/my_param
my_param
You can place
authorization: {
type: 'basic',
name: 'user_name',
pass: 'some_password'
}
directly on your stack:
{
myStack: {
authorization: {
type: 'basic',
name: 'my',
pass: 'pass'
},
routes: {
'/': {
methods: {
'get': getRoot
}
}
}
}
}
or directly on your routes:
{
myStack: {
routes: {
'/': {
authorization: {
type: 'basic',
name: 'my',
pass: 'pass'
},
methods: {
'get': getRoot
}
}
}
}
}
Nested authorizations not tested!