Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/forthedamn/koa-context-loader
load anything to koa context
https://github.com/forthedamn/koa-context-loader
context file-loader koa koa-context koa-context-loader
Last synced: 21 days ago
JSON representation
load anything to koa context
- Host: GitHub
- URL: https://github.com/forthedamn/koa-context-loader
- Owner: forthedamn
- License: mit
- Created: 2017-12-26T03:07:24.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2017-12-26T05:59:40.000Z (about 7 years ago)
- Last Synced: 2024-12-14T19:44:49.104Z (about 2 months ago)
- Topics: context, file-loader, koa, koa-context, koa-context-loader
- Language: JavaScript
- Size: 39.1 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# koa-context-loader
[![NPM version][npm-image]][npm-url]
[![build status](https://img.shields.io/travis/forthedamn/koa-context-loader.svg)](https://travis-ci.org/forthedamn/koa-context-loader)
[![code coverage](https://img.shields.io/codecov/c/github/forthedamn/koa-context-loader.svg)](https://codecov.io/gh/forthedamn/koa-context-loader)
[![license](https://img.shields.io/github/license/forthedamn/koa-context-loader.svg)](LICENSE)[npm-image]: https://img.shields.io/npm/v/koa-context-loader.svg?style=flat-square
[npm-url]: https://npmjs.org/package/koa-context-loader> load file module into app.context
## Install
```sh
npm install koa-context-loaderyarn add koa-context-loader
```## Usage
```js
// ./service/user.jsmodule.exports = {
getUserId() {
return 123;
}
}// ./app.js
const Koa = require('koa');
const app = new Koa();
const loader = require('koa-context-loader');
const path = require('path');const options = {
service: path.resolve(__dirname, './service'),
alias: 'path'
}loader(app.context, options)
app.use((ctx, next) => {
// ctx[alias][filename][export_method]
const id = ctx.service.user.getUserId(); // id:123
});```
### API
#### options {alias: keyof options, path: string}
```
options = {
alias: path
}
```> path must be absolute