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

@kuankuan/static-file-server-components

v0.1.3

Published

static file server components

Downloads

5

Readme

@kuankuan/static-file-server-components

@kuankuan/static-file-server-components 是一个用于静态文件服务器的组件,可以轻松地搭建一个基于 Node.js 的静态文件服务器。

安装

使用 npm 进行安装:

npm install @kuankuan/static-file-server-components

使用

import staticFileServerComponent from "@kuankuan/static-file-server-components";

const config = {
    urlPrefix: "/static",
    rootDir: "/path/to/root",
    // 可选配置项
    dirDefaultEntries: ["index.html"],
    mimeTypes: {
        ".html": "text/html",
        ".css": "text/css",
        // ...
    },
    onNotFound: async function (component, req, res, target) {
        // 处理文件未找到的情况
    },
    onDir: async function (component, req, res, target) {
        // 处理目录访问的情况
    },
    onFile: async function (component, req, res, target) {
        // 处理文件访问的情况
    },
    onError: async function (component, req, res, target, err) {
        // 处理错误的情况
    },
    on404: async function (component, req, res, target) {
        // 处理 404 错误的情况
    },
    on403: async function (component, req, res, target) {
        // 处理 403 错误的情况
    },
    on500: async function (component, req, res, target, err) {
        // 处理 500 错误的情况
    }
};

const server = new staticFileServerComponent(config);

// 处理请求
server.onRequest(req, res);

配置项

  • urlPrefix:URL 前缀,用于匹配静态文件请求。
  • rootDir:静态文件根目录。
  • dirDefaultEntries:默认目录入口文件列表,默认为 ["index.html"]
  • mimeTypes:文件扩展名与 MIME 类型的映射表,默认使用内置的 MIME 类型表。
  • onNotFound:文件未找到时的处理函数。
  • onDir:目录访问时的处理函数。
  • onFile:文件访问时的处理函数。
  • onError:错误处理函数。
  • on404:处理 404 错误的函数。
  • on403:处理 403 错误的函数。
  • on500:处理 500 错误的函数。

开源信息

本项目使用MulanPSL-2.0协议开源,详情参见LICENSE

Gitee|GitHub|GitLab