-
Notifications
You must be signed in to change notification settings - Fork 369
WIP feat: server config doc #7092
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
base: main
Are you sure you want to change the base?
Conversation
|
✅ Deploy Preview for modernjs-byted ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
bc4a79f
to
3147393
Compare
|
||
项目目录下创建 `server/modern.server.ts` 文件,可以在这个文件中配置**中间件**、**渲染中间件**与**服务端插件**来扩展 Server。 | ||
|
||
中间件的执行顺序是: Middleware => PluginMiddleware => RenderMiddleware => PluginRenderMiddleware。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
逗号中英文哈。另外这里可以直接有个图,PluginRenderMiddleware 对于用户来说可能不好理解,这里也还没有讲到 plugin 能做什么,感觉可以表述成在 plugin 中定义的 renderMiddleware
method?: 'options' | 'get' | 'post' | 'put' | 'delete' | 'patch' | 'all'; | ||
handler: MiddlewareHandler | MiddlewareHandler[]; | ||
before?: Array<MiddlewareObj['name']>; | ||
order?: MiddlewareOrder; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
order / before 可以先不透露出去。
Middleware 支持在 Modern.js 服务的**请求处理**与**页面路由**的流程前后,执行自定义逻辑。 | ||
|
||
:::note | ||
BFF 场景只有运行时框架为 Hono 时,BFF 路由才会经过 Middleware。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里最好能说明什么是「运行时框架为 Hono」。或者等 Hono BFF 那部分文档有了,下掉 express 和 koa 之后就不用提了。
|
||
### RenderMiddleware | ||
|
||
Modern.js 支持为 Server 添加渲染中间件,支持在处理页面路由的前后执行自定义逻辑 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
少了个标点:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
另外感觉这部分描述和前面中间件的描述,没有办法很好的区分开来。我理解 RenderMiddleware 更像是一个语法糖,减少用户对页面路由做匹配。是不是可以从功能上说明下两者的差异:
- 如果中间件的能力既要用在接口路由(BFF)上,也要用在页面路由上,可以用 middleware
- 如果只需要页面渲染,我们也准备了 xxx
import { defer } from '@modern-js/runtime/router'; | ||
|
||
export default () => { | ||
const ctx = useHonoContext(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里例子现在直接能用的了吗,不用开启 bff.enableHandleWeb
了是吗
# 自定义 Web Server(不推荐) | ||
|
||
:::warning | ||
自定义 Web Server 兼容但不再推荐使用,扩展 Server 能力请移步 [自定义 Server](/zh/guides/advanced-features/custom-server.html),迁移指南参考 [迁移至新版自定义 Server](/zh/guides/advanced-features/web-server.html#%E8%BF%81%E7%A7%BB%E8%87%B3%E6%96%B0%E7%89%88%E8%87%AA%E5%AE%9A%E4%B9%89-server)。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这链接不用加 /zh 也能自动跳转的~这样写内部跳转不了了
| :----------------------- | :---------------------------- | :------------------------------------------------------------------------ | | ||
| `c.request` | `c.req.raw` | 参考 [HonoRequest raw](https://hono.dev/docs/api/request#raw) 文档 | | ||
| `c.response` | `c.res` | 参考 [Hono Context res](https://hono.dev/docs/api/context#res) 文档 | | ||
| `c.route` | `c.get('route')` | 获取应用上下文信息。 | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
就他多个句号
| UnstableMiddleware | Hono | 说明 | | ||
| :----------------------- | :---------------------------- | :----------------------------- | | ||
| `router.redirect` | `c.redirect` | 参考 [Hono Context redirect](https://hono.dev/docs/api/context#redirect) 文档 | | ||
| `router.rewrite` | - | 暂时没有提供对应的能力 | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mark 一下,这个后续还要提供对应的能力。
Summary
Related Links
Checklist
pnpm run change
.