{"id":23131268,"url":"https://github.com/emartech/boar-koa-server","last_synced_at":"2025-08-17T08:31:20.247Z","repository":{"id":57111326,"uuid":"102471627","full_name":"emartech/boar-koa-server","owner":"emartech","description":null,"archived":false,"fork":false,"pushed_at":"2024-01-09T14:06:47.000Z","size":321,"stargazers_count":0,"open_issues_count":7,"forks_count":3,"subscribers_count":31,"default_branch":"master","last_synced_at":"2024-04-14T07:40:51.905Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/emartech.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-09-05T11:12:45.000Z","updated_at":"2024-02-06T15:17:03.000Z","dependencies_parsed_at":"2024-01-09T15:30:18.572Z","dependency_job_id":"70deb132-e9c1-4be2-8e6b-8e790cc0e0b8","html_url":"https://github.com/emartech/boar-koa-server","commit_stats":{"total_commits":29,"total_committers":8,"mean_commits":3.625,"dds":0.7586206896551724,"last_synced_commit":"56f481e0fa797b005d103e2727e940d6934e7618"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emartech%2Fboar-koa-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emartech%2Fboar-koa-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emartech%2Fboar-koa-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emartech%2Fboar-koa-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/emartech","download_url":"https://codeload.github.com/emartech/boar-koa-server/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230105981,"owners_count":18173954,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-17T11:12:29.769Z","updated_at":"2024-12-17T11:12:30.482Z","avatar_url":"https://github.com/emartech.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Boar Koa Server\n\n## Example usage for app\n\nput these lines in your server.js\n``` javascript\n  const Koa = require('koa');\n  const path = require('path');\n  const koaApp = module.exports = new Koa();\n  const config = require('./config');\n  const App = require('@emartech/boar-koa-server').app;\n\n  const app = new App(koaApp);\n  app.loadControllers(path.join(config.root, 'controllers'));\n\n  if (!module.parent) { app.listen(config.port); }\n```\n\n## Add middleware for your app\n``` javascript\n  const cors = require('koa-cors');\n  const app = new App(koaApp);\n  app.addMiddleware(cors());\n```\n\n## Build-in Middlewares\n\n### Cors Support ([@koa/cors](https://www.npmjs.com/package/@koa/cors))\n\n``` javascript\n  app.addCorsSupportMiddleware();\n```\n\nAllowed settings :\n``` javascript\n  app.addCorsSupportMiddleware({\n    allowOrigin: '*', // `Access-Control-Allow-Origin`, * or a regex to filter allowed origins (for instance /emarsys.(com|net)$/)\n    allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH', // `Access-Control-Allow-Methods`\n  });\n```\n\n**⚠️ WARNING ⚠️** : \nNot specifying an allowed origin made the middleware always return an `Access-Control-Allow-Origin` header with the value of the origin from the request. This behavior completely disables one of the most crucial elements of browsers - the Same Origin Policy (SOP), this could cause a very serious security threat to the users of this middleware.\n\nSince version `2.0.0`, the package is based `@koa/cors@5.0.0` which\n[disables this behavior](https://www.npmjs.com/package/@koa/cors/v/5.0.0#breaking-change-between-50-and-40).\nIt is **highly recommended** to specify a list of allowed origins.\n\n### Method Override ([koa-methodoverwrite](https://github.com/koa-modules/methodoverride))\n\n``` javascript\n  app.addMethodOverrideMiddleware();\n```\n\n### Body Parse ([koa-bodyparser](https://github.com/koajs/body-parser))\n\n| Param | Type  | Description |\n| ----- | ----- | ----------- |\n| __options__ | `Object` | [More info.](https://github.com/koajs/bodyparser#options) |\n\n``` javascript\n  app.addBodyParseMiddleware(options);\n```\n\n### Request Id ([koa-requestid](https://github.com/seegno/koa-requestid))\n\n| Param | Type  | Description |\n| ----- | ----- | ----------- |\n| __options__ | `Object` | _optional_ |\n| ↳header | `String` | The name of the header to read the id on the request, `false` to disable. |\n| ↳query  | `String` | The name of the header to read the id on the query string, `false` to disable. |\n| ↳expose | `String` | The name of the header to expose the id on the response, `false` to disable. |\n\n``` javascript\n  app.addRequestIdmiddleware(options);\n```\n\n### Enforce SSL ([koa-ssl](https://github.com/jclem/koa-ssl))\n\n| Param | Type  | Description |\n| ----- | ----- | ----------- |\n| __options__ | `Object` | [More info.](https://github.com/jclem/koa-ssl#use) |\n\n``` javascript\n  app.addEnforceSSLMiddleware();\n```\n\nIf your application is running behind reverse proxy (like Heroku) you should set the trustProxy configuration option to *true* in order to process the x-forwarded-proto header.\n\n``` javascript\n  const app = new App(koaApp);\n  app.addEnforceSSLMiddleware({ trustProxy: true });\n```\n\n__Note__: if you use this middleware EnforceSSL middleware should be the first you add.\n\n### Security\nProvides middlewares for setting up various security related HTTP headers.\n\n| Param | Type  | Description |\n| ----- | ----- | ----------- |\n| __options__ | `Object` |  |\n| ↳csp | `Object` | [More info.](https://github.com/helmetjs/csp) Learn more: [CSP quick reference](http://content-security-policy.com/) |\n| ↳hsts | `Object` | [More info.](https://github.com/helmetjs/hsts) Learn more: [OWASP HSTS page](https://www.owasp.org/index.php/HTTP_Strict_Transport_Security) |\n| ↳useXssFilter | `Boolean` | If `true`, [x-xss-protection](https://github.com/helmetjs/x-xss-protection) middleware will be included. Default: `true` |\n| ↳useNoSniff | `Boolean` |  If `true`, [dont-sniff-mimetype](https://github.com/helmetjs/dont-sniff-mimetype) middleware will be included. Default: `true` |\n| ↳referrerPolicy| `Boolean,Object` | If`{ policy: 'same-origin'}`, [referrer-policy](https://github.com/helmetjs/referrer-policy) middleware will be included. Default `false` |\n\n``` javascript\n  app.addSecurityMiddlewares(options);\n```\n\n#### Default configuration\n``` javascript\n  {\n    csp: {\n      directives: {\n        defaultSrc: [\"'self'\"],\n        scriptSrc: [\"'self'\"],\n        styleSrc: [\"'self'\"],\n        imgSrc: [\"'self'\"],\n        frameAncestors: [\"'self'\"],\n        reportUri: 'about:blank'\n      },\n      reportOnly: true\n    },\n    hsts: {\n      maxAge: 30,\n      includeSubDomains: true,\n      preload: false\n    },\n    useXssFilter: true,\n    useNoSniff: true,\n    referrerPolicy: false\n  }\n```\n\n\n## Libraries\n\n### ControllerFactory\n``` javascript\n  var ControllerFactory = require('@emartech/boar-koa-server').lib.controllerFactory;\n\n  module.exports = ControllerFactory.create(function(router) {\n    router.get('/', ControllerFactory.load('main/actions/get'));\n    router.get('/healthcheck', ControllerFactory.load('main/actions/healthcheck/get'));\n    router.get('/list', ControllerFactory.loadByAcceptType('main/actions/list/get'));\n  });\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femartech%2Fboar-koa-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femartech%2Fboar-koa-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femartech%2Fboar-koa-server/lists"}