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

quick-koa-server

v1.1.6

Published

快速构建 koa 服务

Downloads

18

Readme

quick-koa-server

快速构建 koa 服务

功能概览

  • 对 quick-koa-server 构建的服务配置跨域(拦截 OPTIONS 请求定向放行)
    • 支持同时配置多个跨域
    • 支持对常见跨域内容项进行单独配置
  • 内置前端渲染 historyApiFallback
  • 支持对前端根页面(/index)注入环境变量(基于 koa-ejs)
  • 静态资源访问服务
  • 支持自由扩展中间件
  • 配置生成 node 本地服务器
    • 支持同时配置多个服务目录、路由
    • 自动生成路由,支持扫描深层目录
    • 自动过滤特殊目录、文件,仅保留有效 router 导出
  • 配置生成网关服务
    • 支持根据环境变量转发指定目标地址
    • 支持对请求头进行配置化放行,默认拦截所有请求头信息
    • 支持自定义 timeout,默认 6e4
    • 支持转发上传类接口
    • 支持转发下载类接口
  • 支持配置健康检查请求

配置介绍

  • koaStaticOpt koa-static 配置
  • koaEjsOpt koa-ejs 配置
  • koaBodyOpt koa-body 配置
  • CORSOpts 跨域配置
  • getwayOpt 网关配置,支持 REST 接口
  • apiOpts node 服务配置
  • passHeaders 允许透传的请求头,除常用 headers 外默认拦截所有请求头
  • processEnvKey 在 process.env 中获取环境变量的 key,默认 'DEPLOY_ENV'
  • timeout 请求超时时间(单位毫秒),默认 6e4
  • healthPath 健康检查请求地址(一般用于校验 node 服务是否可用),默认 '/health'

使用示例

import QServer from 'quick-koa-server';

const app = QServer({
  koaStaticOpt: { root: '/dist' },
  koaEjsOpt: { root: '/dist', layout: 'index', viewExt: 'html', cache: false, debug: false },
  CORSOpts: [{ origin: 'xxx.com', headers: ['cookie'] }],
  getwayOpt: {
    '/api/xxx': {
      target: 'xxx.com',
      pathRewrite: { '^/api/xxx': '' },
    },
  },
  apiOpts: [{ path: '/api/qserver/xxx', dir: '/xxx' }],
  passHeaders: ['cookie'],
});

app.listen(8080, () => {
  console.log('Success: Ready at http://localhost:8080');
});

自由扩展本地路由示例

import * as path from 'path';
import * as Router from 'koa-router';
import { getApiRouter } from 'quick-koa-server/lib/routes/api';

const router = new Router();
getApiRouter(router, {
  path: '/api/qserver/factory',
  dir: path.resolve(__dirname, './factory/api'),
});

app.use(router.routes());