npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

koa-server-static

v1.0.0

Published

koa-static的增强版,支持动态选择pc端还是移动端的静态文件,coderlibs官方提供的Koa静态文件服务中间件

Downloads

3

Readme

koa-server-static

Koa 静态文件服务中间件,可以根据不同设备(pc端,移动端)动态获取资源

该中间件由coderlibs 官方出品

Installation

$ npm install koa-server-static

API

const Koa = require('koa');
const app = new Koa();
app.use(require('koa-server-static')(root, opts)); // 获取静态资源
app.listen(8080, () => {
    console.log('Server is running at http://localhost:' + port);
});

Options

  • facility 代表设备类型,不设置则代表不区分,值可传 pc | md
  • maxage 浏览器缓存的最大年龄(以毫秒为单位)。默认为 0
  • hidden 允许传输隐藏文件。默认为false
  • index 默认文件名,默认为 'index.html'
  • defer 如果为 true,则在 之后服务return next(),允许任何下游中间件首先响应。
  • gzip 当客户端支持 gzip 并且请求的扩展名为 .gz 的文件存在时,尝试自动提供文件的 gzip 版本。默认为真。
  • brotli 当客户端支持 brotli 并且请求的扩展名为 .br 的文件存在时,尝试自动提供文件的 brotli 版本(注意,brotli 只能通过 https 接受)。默认为真。
  • setHeaders 函数在响应中设置自定义标头。
  • extensions 当 URL 中没有足够的扩展名时,尝试从传递的数组中匹配扩展名来搜索文件。首先找到的服务。(默认为false)

示例1 facility

const Koa = require('koa');
const app = new Koa();
const static = require('koa-server-static');
const path = require('path');
// facility代表设备类型,不设置则代表不区分
app.use(static(path.join(__dirname + '/public/pc'),{facility:'pc'})); // 当设备为电脑端时(Personal Computer)获取端静态资源

app.use(static(path.join(__dirname + '/public/app'),{facility:'md'})); // 当设备为手机端时(Mobile Device)获取端静态资源

示例2 defer

const Koa = require('koa');
const app = new Koa();
const static = require('koa-server-static');
const path = require('path');
// defer代表是否需要最后执行此中间件,不设置则立马执行
app.use(static(path.join(__dirname + '/public'),{defer:true})); // 等待其他中间件执行完后最后再加载当前中间件