<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國際加速解決方案。 廣告
                ## Helmet 通過適當地設置 `HTTP` 頭,[Helmet](https://github.com/helmetjs/helmet) 可以幫助保護您的應用免受一些眾所周知的 `Web` 漏洞的影響。通常,`Helmet` 只是`14`個較小的中間件函數的集合,它們設置與安全相關的 `HTTP` 頭([閱讀更多](https://github.com/helmetjs/helmet#how-it-works))。 > 要在全局使用`Helmet`,需要在調用`app.use()`之前或者可能調用`app.use()`函數之前注冊。這是由平臺底層機制中(EXpress或者Fastify)中間件/路徑的定義決定的。如果在定義路徑之后使用`helmet`或者`cors`中間件,其之前的路徑將不會應用這些中間件,而僅在定義之后的路徑中應用。 ### 在Express中使用(默認) 首先,安裝所需的包: ```bash $ npm i --save helmet ``` 安裝完成后,將其應用為全局中間件。 ```typescript import * as helmet from 'helmet'; // somewhere in your initialization file app.use(helmet()); ``` > 如果在引入`helmet`時返回`This expression is not callable`錯誤。你可能需要將項目中`tsconfig.json`文件的`allowSyntheticDefaultImports`和`esModuleInterop`選項配置為`true`。在這種情況下,將引入聲明修改為:`import helmet from 'helmet'`。 ### 在Fastify中使用 如果使用`FastifyAdapter`,安裝`fastify-helmet`包: ```bash $ npm i --save fastify-helmet ``` `fastify-helmet`需要作為`Fastify`插件而不是中間件使用,例如,用`app.register()`調用。 ```typescript import * as helmet from 'fastify-helmet'; // somewhere in your initialization file app.register(helmet); ``` > 在使用`apollo-server-fastify`和`fastify-helmet`時,在`GraphQL`應用中與[CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP)使用時可能出問題,需要如下配置CSP。 ```TypeScript app.register(helmet, { contentSecurityPolicy: { directives: { defaultSrc: [`'self'`], styleSrc: [`'self'`, `'unsafe-inline'`, 'cdn.jsdelivr.net', 'fonts.googleapis.com'], fontSrc: [`'self'`, 'fonts.gstatic.com'], imgSrc: [`'self'`, 'data:', 'cdn.jsdelivr.net'], scriptSrc: [`'self'`, `https: 'unsafe-inline'`, `cdn.jsdelivr.net`], }, }, }); // If you are not going to use CSP at all, you can use this: app.register(helmet, { contentSecurityPolicy: false, }); ```
                  <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>

                              哎呀哎呀视频在线观看