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

运行时上下文是否可以加入原生req? #290

Closed
moonrailgun opened this issue Aug 24, 2022 · 8 comments
Closed

运行时上下文是否可以加入原生req? #290

moonrailgun opened this issue Aug 24, 2022 · 8 comments
Labels
feature New feature or request good first issue Good for newcomers next-release

Comments

@moonrailgun
Copy link
Contributor

不清楚是否刻意没有加入?

image

@maslow
Copy link
Member

maslow commented Aug 26, 2022

其实是可以考虑直接使用原生 req,这块应该没什么问题。
最初是想制定一个 统一的 入参,未来可以有更多扩展手段。

@moonrailgun
Copy link
Contributor Author

原生req有一个好处是,可以直接用现成的一些轮子去做一些事情。

我觉得作为一个补充手段其实是非常实用的

@maslow
Copy link
Member

maslow commented Aug 26, 2022

有道理, 能具体举例子吗,方便理解

@moonrailgun
Copy link
Contributor Author

比方说我有一个koa应用。那我就可以直接使用 koa.callback()(req, res) 来直接把现成的应用集成到 laf 中

这是一个vercel的case
https://github.com/DIYgod/RSSHub/blob/master/api/vercel.js

@maslow
Copy link
Member

maslow commented Aug 26, 2022

这个需求很有价值,有几个疑问要请教:

  1. 当前 app-service 是用 express 实现的, 如果暴露 req, res 当前也是 express 的,还是会出现不能直接用的情况
  2. 是否有充分的理由切为 koa 实现
  3. 无论暴露 express req / koa req,都与当前的 interface 不兼容,现有云函数的兼容有没有好的手段

最重要的是,使用 koa req interface,未来是否还会面临此 interface 的调整, 会再次面对 问题(3),存量生态产物的处理是关键问题。

@moonrailgun
Copy link
Contributor Author

首先不是要切换koa。

建议使用node http 的 req对象。完整的名字我记得叫 incomingrequest(可能不对) 。因为所有的框架都需要兼容这个对象的数据(基于这个的原始数据来解析)

express的req对象是集成自nodejs的原生req对象的。这个没有问题。

建议是额外增加req的暴露(反正都暴露res了),这个是增加更新,不会对现有的项目产生break change的吧

@maslow
Copy link
Member

maslow commented Aug 26, 2022

了解,认同 extra req 的方式,没有 break change。
另外,node native req (IncomingRequest) 等我再看一下其参数和结构, 应该没问题

@maslow
Copy link
Member

maslow commented Sep 13, 2022

@moonrailgun 是否考虑直接给 app-service 提 pr 增加 native req?

moonrailgun added a commit to moonrailgun/laf that referenced this issue Sep 13, 2022
@maslow maslow added good first issue Good for newcomers next-release wip work in progress feature New feature or request labels Sep 14, 2022
maslow added a commit that referenced this issue Sep 14, 2022
Signed-off-by: maslow <wangfugen@126.com>
@maslow maslow removed the wip work in progress label Sep 14, 2022
@maslow maslow closed this as completed Sep 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request good first issue Good for newcomers next-release
Projects
None yet
Development

No branches or pull requests

2 participants