Cell - 静态文件服务组件
从后端提供前端构建。fullstack 模板依赖它;没有前端的项目不需要它。
bash
npm install @celljs/serve-static它提供 serveStatic.root(默认 ${paths.public},构建输出的 public/ 目录),使用 Cell 自己的文件发送程序:Content-Type、弱 ETag、Last-Modified、Cache-Control、对新鲜请求的 304、对失败的 If-Match / If-Unmodified-Since 的 412、单字节范围(206 / 416)、忽略 dotfiles,拒绝离开 root 的路径。使用 spa: true(默认)时未知路径获得 /index.html,所以客户端路由在重新加载时工作。没有前端目录时,请求通过。
serveStatic.options:maxAge(毫秒,默认一年)、immutable(默认 true)、htmlMaxAge(HTML 文件和 Web 应用清单的 Cache-Control,.webmanifest,默认 0)、headers(添加到每个文件)、index(默认 index.html,false 表示无)、extensions(路径无后缀时尝试)、dotfiles(ignore 默认、allow、deny)、redirect(从目录重定向到其带 / 的路径,301)、acceptRanges、cacheControl、etag、lastModified(默认 true)、fallthrough(默认 true)。
使用 cell build --single,文件被嵌入到服务端包中,从内存中以相同的 header 提供。