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

serve-yyl-ssr

v0.3.10

Published

yyl-ssr 用 服务端 中间件

Downloads

4

Readme

serve-yyl-ssr

yyl-ssr 用 服务端 中间件

usage

直接看 types

entry

import { Req, Res } from './types'
import { YylSsrOption } from './yylSsr'
export { ssrRedis } from './redis'
export declare function serveYylSsr<O extends Res = Res, I extends Req = Req>(
  option: YylSsrOption<O, I>
): (req: I, res: O, next: import('./yylSsr').NextFunction) => void

redis

import { RedisClient } from 'redis'
import { Logger } from './types'
export interface SsrRedisOption {
  port?: number
  log: Logger
}
export interface SsrRedisHandle {
  /** 获取 缓存 */
  get<T extends RedisData = {}>(key: string): Promise<T | undefined>
  /** 设置缓存 */
  set<T extends RedisData = {}>(key: string, val: T): void
}
/** ssr redis */
export interface SsrRedis {
  /** 是否支持 redis */
  isSupported: boolean
  /** 日志输出设置 */
  log: Logger
  /** redis client */
  client: RedisClient | undefined
  /** 是否已经初始化 */
  inited: boolean
  /** 初始化 redis */
  init(option: SsrRedisOption): SsrRedisHandle
  /** 终止 链接 redis */
  end(): void
}
export interface RedisData {
  [key: string]: string
}
export declare const ssrRedis: SsrRedis

yylSsr

/// <reference types="node" />
import { Stream } from 'stream'
import { Logger, Req, Res } from './types'
/** next function 定义 */
export declare type NextFunction = (err?: any) => void
/** render 结果 */
export declare type RenderResult = [Error | undefined, string | undefined | Stream]
/** 渲染-参数 */
interface ServeYylSsrOptionRenderOption<O extends Res, I extends Req> {
  res: O
  req: I
  next: NextFunction
}
/** cache 类型 */
export declare enum CacheType {
  Redis = 'redis',
  None = 'none'
}
/** yylSsr - option */
export interface YylSsrOption<O extends Res, I extends Req> {
  /** 渲染 */
  render: (op: ServeYylSsrOptionRenderOption<O, I>) => Promise<RenderResult> | RenderResult
  /** 是否处于开发环境 */
  dev?: boolean
  /** 日志输出回调 */
  logger?: Logger
  /** redis 服务端口 */
  redisPort?: number
  /** 缓存有效时间 */
  cacheExpire?: number
  /** 缓存类型 */
  cacheType?: CacheType
  /** 缓存标识 */
  cacheMark?: string | ((req: I) => string)
}
export declare type YylSsrProperty<O extends Res, I extends Req> = Required<YylSsrOption<O, I>>
export declare type YylSsrHandler<O extends Res, I extends Req> = () => (
  req: I,
  res: O,
  next: NextFunction
) => void
export interface CtxRenderProps<I extends Req, O extends Res> {
  req: I
  res: O
  ctx: Promise<RenderResult> | RenderResult
  pathname: string
  next: NextFunction
  cacheMark: string
}
/** yylSsr - 类 */
export declare class YylSsr<O extends Res = Res, I extends Req = Req> {
  /** 日志函数 */
  private logger
  /** 渲染函数 */
  private render
  /** 缓存操作句柄 */
  private redis?
  /** 缓存有效时间 */
  private cacheExpire
  /** 缓存类型 */
  private cacheType
  /** 缓存标识 */
  private cacheMark
  /** 对外函数 */
  apply: YylSsrHandler<O, I>
  /** 初始化 */
  constructor(option: YylSsrOption<O, I>)
  private parseCacheMark
  private ctxRender
  private ssrRender
  /** 缓存保存 */
  private setCache
  /** 缓存提取 */
  private getCache
  /** 日志 */
  private log
}
export {}