Request
Handle basic tasks for koajs.
Example config:
const Koa = require('koa');
const {Request} = require('@smpx/koa-request');
const app = new Koa();
const requestOptions = {
middleware: true,
baseDomain: 'smartprix.com',
rateLimit: {
interval: {min: 1},
max: 10,
skip(ctx) {
return false;
},
},
basicAuth: {
enabled: true,
skipOnProxy: true,
skipOnLocalhost: true,
skip(ctx) {
return false;
},
name: 'admin',
pass: 'admin',
},
staticPaths: [
{
path: '/',
root: `${__dirname}/public`,
skip(ctx) {
return ctx.path.startWith('/robots.txt');
}
},
{
path: '/static',
root: `${__dirname}/static`,
allowOrigins: '*',
immutable: true,
},
{
path: '/files',
root: `${__dirname}/files`,
immutable: true,
async getPath(ctx) {
return DB.fetch('paths', ctx.path);
},
},
],
banBots: {
commonBots: true,
userAgents: [
'80legs',
],
ips: [
'27.210.',
],
email: 'a@b.com',
}
};
Request.install(app, requestOptions);