Inject global

Edit

Somehow we want to require koa-cola project files but without running the project, if the file contain global refer which base on run-time like app.xxx, this will thow a exception, in this particular situation we need use reqInject to inject global.app.

1
2
3
4
5
6
7
8
import { reqInject } from 'koa-cola'
let user;
reqInject(function(){
// after injection, we can require any files inside project.
user = require('./api/models/user').default
// or get the global variable directly
let config = app.config;
});