0.0.3 • Published 7 months ago

one-server-http v0.0.3

Weekly downloads
-
License
-
Repository
-
Last release
7 months ago

It's a toolkit for simplfing development, including several common-used Server Protocols(http1.1, https, http2).

Functions

interface HttpConfig {
  port?: number; // 服务端口号, 不设置的会使用默认值
  useHttps?: boolean; // 是否HTTPs服务
  useHttp2?: boolean; // 是否HTTP2服务
  credentials?: { key: string; cert: string }; // SSL证书
  allowHTTP1?: boolean; // 不支持HTTP2时是否兼容HTTP1.1
  jwtSecretKey?: string; // JWT加密密钥
  cors?: string | string[]; // 跨域设置, *或者origin数组
  urlencodedLimit?: string; // express访问请求体大小限制
  public_path?:string; // 静态网页
}

/**
 * JWT签名
 * @param payload 
 * @param secret 
 * @param options 
 * @returns 
 */
function authSign(payload:object, secret:string, options?:SignOptions): string;
/**
 * JWT验证
 * @param token 
 * @param secret 
 * @returns 
 */
function authVerify(token:string, secret:string): Promise<any>;

class HttpServer {
  // 构造器
  constructor(filename:string);
  constructor(options:HttpConfig);

  /**
   * 自定义路由
   * @param apis 
   * @returns 
   */
  router(apis:(app:any, jwt:(req: Request, res: Response, next: any)=>any)=>void): this;

  /**
   * 启动服务
   */
  public start(callback?:(port:number, protocol?:string)=>void): this;
}
0.0.3

7 months ago

0.0.2

7 months ago

0.0.1

7 months ago