<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ## 性能(Fastify) 在底層,`Nest` 使用了[Express](https://expressjs.com/)框架,但如前所述,它提供了與各種其他庫的兼容性,例如 [Fastify](https://github.com/fastify/fastify)。`Nest`應用一個框架適配器,其主要功能是代理中間件和處理器到適當的特定庫應用中,從而達到框架的獨立性。 > 注意要應用框架適配器,目標庫必須提供在`Express` 類似的請求/響應管道處理 `Fastify` 非常適合這里,因為它以與 `express` 類似的方式解決設計問題。然而,`fastify` 的速度要快得多,達到了幾乎兩倍的基準測試結果。問題是,為什么 `Nest` 仍然使用 `express` 作為默認的 HTTP 提供程序?因為 `express` 是應用廣泛、廣為人知的,而且擁有一套龐大的兼容中間件。 但是由于 `Nest` 提供了框架獨立性,因此您可以輕松地在它們之間遷移。當您對快速的性能給予很高的評價時,`Fastify` 可能是更好的選擇。要使用 `Fastify`,只需選擇 `FastifyAdapter`本章所示的內置功能。 ### 安裝 首先,我們需要安裝所需的軟件包: ```bash $ npm i --save @nestjs/platform-fastify ``` ### 適配器(Adapter) 安裝 fastify 后,我們可以使用 `FastifyAdapter`。 >main.ts ```typescript import { NestFactory } from '@nestjs/core'; import { FastifyAdapter, NestFastifyApplication } from '@nestjs/platform-fastify'; import { ApplicationModule } from './app.module'; async function bootstrap() { const app = await NestFactory.create<NestFastifyApplication>(ApplicationModule, new FastifyAdapter()); await app.listen(3000); } bootstrap(); ``` 默認情況下,`Fastify`僅在 `localhost 127.0.0.1` 接口上監聽(了解[更多](https://www.fastify.io/docs/latest/Getting-Started/#your-first-server)信息)。如果要接受其他主機上的連接,則應`'0.0.0.0'`在 `listen()` 呼叫中指定: ```typescript async function bootstrap() { const app = await NestFactory.create<NestFastifyApplication>(ApplicationModule, new FastifyAdapter()); await app.listen(3000, '0.0.0.0'); } ``` ### 平臺特定的軟件包 請記住,當您使用 `FastifyAdapter` 時,`Nest` 使用 `Fastify` 作為 `HTTP` 提供程序。 這意味著依賴 `Express` 的每個配方都可能不再起作用。 您應該改為使用 `Fastify` 等效程序包。 ### 重定向響應 `Fastify` 處理重定向響應的方式與 `Express` 有所不同。要使用 `Fastify` 進行正確的重定向,請同時返回狀態代碼和 `URL`,如下所示: ```typescript @Get() index(@Res() res) { res.status(302).redirect('/login'); } ``` ### Fastify 選項 您可以通過構造函數將選項傳遞給 `Fastify`的構造 `FastifyAdapter` 函數。例如: ```typescript new FastifyAdapter({ logger: true }); ``` ### 例子 [這里](https://github.com/nestjs/nest/tree/master/sample/10-fastify)有一個工作示例
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看