Apj
Start with a complete Koa server with zero configuration.
Apj includes Koa packages:
Installation
npm install apj --save
Example
const Apj = require('apj');
new Apj().start();
Dev mode
new Apj({
dev: true
}).start();
Add routes
const app = new Apj();
app.router.get('/my-route', ctx => {
ctx.body = 'hello';
});
app.start();
Use middleware
new Apj({
use: [
async (ctx, next) => {
const start = Date.now();
await next();
const ms = Date.now() - start;
console.log(`${ctx.method} ${ctx.url} - ${ms}ms`);
}
]
});
API
Apj
Kind: global class
new Apj([opt])
Create instance
Param | Type | Default | Description |
---|
[opt] | object | | options
|
[opt.host] | string | "localhost" | host
|
[opt.port] | number | 80 | port
|
[opt.serverOptions] | object | | server options
|
[opt.devPort] | number | 3000 | dev port (when dev is true)
|
[opt.SSLPort] | number | 443 | SSL port
|
[opt.serverSSLOptions] | object | | SSL server options
|
[opt.helmetSettings] | object | | koa-helmet settings
|
[opt.routerSettings] | object | | koa-router settings
|
[opt.bodySettings] | object | | koa-body settings
|
[opt.successSettings] | object | | koa-json-success settings
|
[opt.structSettings] | object | | koa-struct settings
|
[opt.cacheSettings] | object | | koa-incache settings
|
[opt.corsSettings] | object | | @koa/cors@2 settings
|
[opt.sessionSettings] | object | | koa-session settings
|
[opt.viewsSettings] | object | | koa-views settings
|
[opt.loggerSettings] | object | | koa-logger settings
|
[opt.logger] | object | false | active koa-logger
|
[opt.ctx] | object | | Koa context
|
[opt.viewsPath] | string | "./views/" | path to views
|
[opt.staticPath] | string | "./public/" | path to static resources
|
[opt.use] | array | | array of middleware
|
[opt.autoStart] | boolean | false | start on create
|
[opt.responseErrorHandler] | boolean | | manipulate message and code
|
[opt.exposeError] | boolean | | expose all errors
|
apj.start() ⇒ Apj
Start server app
Kind: instance method of Apj
Emits: start
, SSLStart
apj.stop() ⇒ Apj
Stop server app
Kind: instance method of Apj
Emits: stop
, SSLStop
"start"
Triggered on server start
Kind: event emitted by Apj
"SSLStart"
Triggered on SSL server start
Kind: event emitted by Apj
"stop"
Triggered on server stop
Kind: event emitted by Apj
"SSLStop"
Triggered on SSL server stop
Kind: event emitted by Apj
Apj~apj : object
Apj instance
Kind: inner typedef of Apj
Properties
Name | Type | Description |
---|
app | object | Koa instance
|
router | object | router object
|
server | object | server instance
|
SSLServer | object | SSL server instance
|
Changelog
You can view the changelog here
License
Apj is open-sourced software licensed under the MIT license
Author
Fabio Ricali