Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sofa-node应用 怎么在app/rpc/获取app实例 #4309

Closed
345316222 opened this issue May 17, 2020 · 3 comments
Closed

sofa-node应用 怎么在app/rpc/获取app实例 #4309

345316222 opened this issue May 17, 2020 · 3 comments
Assignees

Comments

@345316222
Copy link

345316222 commented May 17, 2020

What happens?

我在app hook文件里给app注册了一个对象,想要在rpc服务实现的方法里面获取这个对象和ctx,从而查询数据库或者做些其他的操作。看官方的案例,实现的方法只能取到的res。那怎么在方法里面获取ctx,app 呢?

app.ts

class AppBootHook {
    app: any
    pool: any
    constructor(app: any) {
        this.app = app;
    }
    async didLoad() {
        // 所有的配置已经加载完毕
        // 可以用来加载应用自定义的文件,启动自定义的服务
        this.pool = initPuppeteerPool();
    }
    async beforeClose() {
        // 在服务重启或者关闭时清除池子
        if (this.pool.drain) {
            await this.pool.drain().then(() => this.pool.clear());
        }
    }
}

app/rpc/rpc.ts

exports.hello = async req => {
     **// 怎么获取app里的pool ?????**
    app.pool.do......
}
@ghost
Copy link

ghost commented May 18, 2020

不知道是不是这个链接地址是答案。自问自答
#3447

@gxcsoccer
Copy link
Contributor

@naxiaoguang 是的

@atian25
Copy link
Member

atian25 commented May 25, 2020

@gxcsoccer 可以 close 了?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants