模极社社区 - 制造业全产业链交流平台

    • 登录
    • 版块
    • 最新
    • 话题
    • 热门
    • 用户
    • 群组

    send静态文件模块 - Node.js参考——模具行业从业者必备知识手册

    社区公告
    1
    1
    1
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • S
      system 2 最后由 编辑

      <h2>send</h2>

      <p>[![NPM Version][npm-version-image]][npm-url]</p>
      <p>[![NPM Downloads][npm-downloads-image]][npm-url]</p>
      <p>[![Linux Build][github-actions-ci-image]][github-actions-ci-url]</p>
      <p>[![Windows Build][appveyor-image]][appveyor-url]</p>
      <p>[![Test Coverage][coveralls-image]][coveralls-url]</p>

      <p>Send is a library for streaming files from the file system as a http response</p>
      <p>supporting partial responses (Ranges), conditional-GET negotiation (If-Match,</p>
      <p>If-Unmodified-Since, If-None-Match, If-Modified-Since), high test coverage,</p>
      <p>and granular events which may be leveraged to take appropriate actions in your</p>
      <p>application or framework.</p>

      <p>Looking to serve up entire folders mapped to URLs? Try <a href="https://www.npmjs.org/package/serve-static">serve-static</a>.</p>

      <h3>Installation</h3>

      <p>This is a <a href="https://nodejs.org/en/">Node.js</a> module available through the</p>
      <p><a href="https://www.npmjs.com/">npm registry</a>. Installation is done using the</p>
      <p><a href="https://docs.npmjs.com/getting-started/installing-npm-packages-locally"><code>npm install</code> command</a>:</p>

      <pre><code>
      $ npm install send
      </code></pre>

      <h3>API</h3>

      <pre><code>
      var send = require('send')
      </code></pre>

      <h4>send(req, path, [options])</h4>

      <p>Create a new <code>SendStream</code> for the given path to send to a <code>res</code>. The <code>req</code> is</p>
      <p>the Node.js HTTP request and the <code>path</code> is a urlencoded path to send (urlencoded,</p>
      <p>not the actual file-system path).</p>

      <p>#### Options</p>

      <p>##### acceptRanges</p>

      <p>Enable or disable accepting ranged requests, defaults to true.</p>
      <p>Disabling this will not send <code>Accept-Ranges</code> and ignore the contents</p>
      <p>of the <code>Range</code> request header.</p>

      <p>##### cacheControl</p>

      <p>Enable or disable setting <code>Cache-Control</code> response header, defaults to</p>
      <p>true. Disabling this will ignore the <code>immutable</code> and <code>maxAge</code> options.</p>

      <p>##### dotfiles</p>

      <p>Set how "dotfiles" are treated when encountered. A dotfile is a file</p>
      <p>or directory that begins with a dot ("."). Note this check is done on</p>
      <p>the path itself without checking if the path actually exists on the</p>
      <p>disk. If <code>root</code> is specified, only the dotfiles above the root are</p>
      <p>checked (i.e. the root itself can be within a dotfile when when set</p>
      <p>to "deny").</p>

      <ul>
      <li><code>'allow'</code> No special treatment for dotfiles.</li>
      <li><code>'deny'</code> Send a 403 for any request for a dotfile.</li>
      <li><code>'ignore'</code> Pretend like the dotfile does not exist and 404.</li>
      </ul>

      <p>The default value is similar to <code>'ignore'</code>, with the exception that</p>
      <p>this default will not ignore the files within a directory that begins</p>
      <p>with a dot, for backward-compatibility.</p>

      <p>##### end</p>

      <p>Byte offset at which the stream ends, defaults to the length of the file</p>
      <p>minus 1. The end is inclusive in the stream, meaning <code>end: 3</code> will include</p>
      <p>the 4th byte in the stream.</p>

      <p>##### etag</p>

      <p>Enable or disable etag generation, defaults to true.</p>

      <p>##### extensions</p>

      <p>If a given file doesn't exist, try appending one of the given extensions,</p>
      <p>in the given order. By default, this is disabled (set to <code>false</code>). An</p>
      <p>example value that will serve extension-less HTML files: <code>['html', 'htm']</code>.</p>
      <p>This is skipped if the requested file already has an extension.</p>

      <p>##### immutable</p>

      <p>Enable or disable the <code>immutable</code> directive in the <code>Cache-Control</code> response</p>
      <p>header, defaults to <code>false</code>. If set to <code>true</code>, the <code>maxAge</code> option should</p>
      <p>also be specified to enable caching. The <code>immutable</code> directive will prevent</p>
      <p>supported clients from making conditional requests during the life of the</p>
      <p><code>maxAge</code> option to check if the file has changed.</p>

      <p>##### index</p>

      <p>By default send supports "index.html" files, to disable this</p>
      <p>set <code>false</code> or to supply a new index pass a string or an array</p>
      <p>in preferred order.</p>

      <p>##### lastModified</p>

      <p>Enable or disable `Last-Modif</p>

      <hr>
      <p>踩过坑的来评论区说说。</p>

      1 条回复 最后回复 回复 引用 0
      • First post
        Last post
      Powered by NodeBB | Contributors