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

只应用于 API #24

Closed
gmonking opened this issue Sep 5, 2017 · 5 comments
Closed

只应用于 API #24

gmonking opened this issue Sep 5, 2017 · 5 comments

Comments

@gmonking
Copy link

gmonking commented Sep 5, 2017

今天第一次用,发现页面也成为了 restc 的页面, 所以有没有一些选项能让我指定只针对某些规则的 url . 或者其他的方式可以绕过不应该转变为 restc 的页面

我目前是这么做的:

if (DEVELOPMENT) {
    app.use(async (ctx, next) => {
        if (ctx.url.indexOf('/api') !== -1) {
            return restc.koa2()(ctx, next)
        }
        return next()
    })
}
@Hujun
Copy link

Hujun commented Sep 26, 2017

同样的问题,应该有restc.koa2({exclude: ['/exclude_url'], path: ['/include_url']}) 这种初始化操作。

@lujjjh
Copy link
Contributor

lujjjh commented Sep 26, 2017

你的需求可以用 koajs/mount 解决,比如:

app.use(mount('/api', restc()))

@Hujun
Copy link

Hujun commented Sep 26, 2017

koa-mount这种方式只解决了include的问题,但没有解决exclude。从本质上来讲这个还是middleware的配置问题,如果再用一个其他middleware来解决的话就不够优雅了。

@gmonking
Copy link
Author

@lujjjh 只是实现需求的话,issue 中也给出了我自己的实现方式,然后看了下源码目前 options 还是没有什么选项的,我认为可以为 options 添加一些选项,让使用这个中间件的体验更好。

@lujjjh
Copy link
Contributor

lujjjh commented Sep 27, 2017

@Hujun @gmonking 欢迎 review #26

@lujjjh lujjjh closed this as completed Jan 26, 2018
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