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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@up-cli/app-core

v1.0.8

Published

Core application server for deployment

Readme

@up-cli/app-core

Node.js 静态服务器核心模块,支持静态文件托管、History 模式和代理转发。

安装

pnpm add @up-cli/app-core

使用

import { run } from '@up-cli/app-core'

await run({
  server: {
    port: 3000,
    publicPath: 'dist',
    historyMode: true,
  },
})

配置文件

在项目根目录创建 up.config.json,启动时自动加载:

{
  "server": {
    "port": 3000,
    "host": "0.0.0.0",
    "publicPath": "public",
    "basePath": "",
    "historyMode": true
  },
  "proxy": {
    "enabled": false,
    "rules": []
  }
}

配置优先级:代码传参 > 配置文件 > 默认值

server

| 字段 | 类型 | 默认值 | 说明 | |------|------|--------|------| | port | number | 3000 | 服务端口(1-65535) | | host | string | 0.0.0.0 | 服务主机地址 | | publicPath | string | public | 静态文件目录 | | basePath | string | "" | 基础路径 | | historyMode | boolean | true | 是否启用 History 模式 |

proxy

| 字段 | 类型 | 默认值 | 说明 | |------|------|--------|------| | enabled | boolean | false | 是否启用代理 | | rules | ProxyRule[] | [] | 代理规则列表 |

ProxyRule

| 字段 | 类型 | 必填 | 说明 | |------|------|------|------| | path | string | 是 | 代理路径前缀 | | target | string | 是 | 目标地址(合法 URL) | | changeOrigin | boolean | 否 | 是否改变源 | | ws | boolean | 否 | 是否支持 WebSocket | | pathRewrite | Record<string, string> | 否 | 路径重写规则 | | headers | Record<string, string> | 否 | 自定义请求头 |

代理配置示例

{
  "proxy": {
    "enabled": true,
    "rules": [
      {
        "path": "/api",
        "target": "http://localhost:8080",
        "changeOrigin": true,
        "pathRewrite": { "^/api": "" }
      }
    ]
  }
}

fileRoutes(文件路由)

支持在 TAF 环境下从配置中心加载文件内容并映射到 HTTP 路径。

{
  "fileRoutes": [
    { "path": "/api/config", "tafFileName": "app-config.json" },
    { "path": "/api/whitelist", "tafFileName": "whitelist.txt" }
  ]
}

| 字段 | 类型 | 说明 | |------|------|------| | path | string | HTTP 请求路径(精确匹配) | | tafFileName | string | TAF 配置中心的文件名 |

工作流程:

  1. 服务启动时读取 fileRoutes 配置
  2. 在 TAF 环境下,通过 @taf/taf-config 加载文件内容到内存
  3. 自动推断 Content-Type(.jsonapplication/json.txttext/plain
  4. 精确匹配路径后返回对应内容
  5. 非 TAF 环境下 fileRoutes 不生效

API

run(options?)

启动服务器。

import { run } from '@up-cli/app-core'

await run({
  root: process.cwd(),
  configFile: 'up.config.json',
  server: { port: 3000 },
  proxy: { enabled: false },
  fileRoutes: []
})

参数说明:

| 参数 | 类型 | 说明 | |------|------|------| | root | string | 项目根目录(默认:process.cwd()) | | configFile | string | 配置文件路径(默认:up.config.json) | | server | Partial<ServerConfig> | 服务器配置覆盖 | | proxy | Partial<ProxyConfig> | 代理配置覆盖 | | fileRoutes | FileRouteRule[] | 文件路由配置覆盖 |

createApp(options)

创建 Koa 应用实例(高级用法)。

import { createApp } from '@up-cli/app-core'

const app = createApp({
  config: upConfig,
  root: process.cwd(),
  fileRouteMap: new Map()
})

isTafEnv()

判断是否为 TAF 环境。

import { isTafEnv } from '@up-cli/app-core'

if (isTafEnv()) {
  // TAF 环境特定逻辑
}

类型导出

import type {
  FileRouteRule,
  ProxyConfig,
  ProxyRule,
  RunOptions,
  ServerConfig,
  UpConfig,
  UpConfigFile,
} from '@up-cli/app-core'