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

@fastcar/server

v0.0.3

Published

服务统一管理框架

Downloads

9

Readme

@fastcar/core框架下创建网络服务器

快速安装

npm install @fastcar/server

使用说明

  • 由应用手动创建服务,并放置ServerApplication下统一进行管理
  • 应用入口开启 @EnableServer
  • 新版本的@fastcar/koa 和 @fastcar/rpc均依赖于server创建服务
  • 生命周期,它的周期均为最后 每次启动或者停止均为最后
  • 支持创建 net http https http2 ssl服务

服务基础配置说明

  • port?: number; //可选 默认80 https默认443
  • protocol?: Protocol; //可选 http http2 或者 https 默认http
  • ssl?: SSLConfig; //可选 ssl 对象中为cert和key 用于支持ssl请求
  • hostname?: string; //可选 当填写0.0.0.0时则不开启ipv6了
import "reflect-metadata";
import { FastCarApplication } from "@fastcar/core";
import { Application, BaseFilePath, BasePath } from "@fastcar/core/annotation";
import { EnableServer } from "@fastcar/server";

@Application
@BasePath(__dirname)
@BaseFilePath(__filename)
@EnableServer
class APP {
 app!: FastCarApplication;
}
new APP();
  • 手动调用server示例
@ApplicationStart(BootPriority.Lowest)
export default class ServerService {
 @Autowired
 protected serverApplication!: ServerApplication;

 @Autowired
 protected app!: FastCarApplication;

 run() {
  let list: ServerConfig[] = this.app.getSetting("server"); //此处为服务器配置列表

  //进行创建
  list.forEach((item) => {
   this.serverApplication.createServer(item, (req: any, res: any) => {
    try {
     if (item.protocol == Protocol.http || item.protocol == Protocol.https || item.protocol == Protocol.http2) {
      res.writeHead(200);
      res.end("hello world\n");
     } else {
      req.end("hello world\n");
     }
    } catch (e) {
     console.error(e);
    }
   });
  });
 }
}
  • 应用配置示例
application:
  name: "simple"
settings:
  server:
    - { port: 1234 } ##默认http请求
    - {
        port: 1235,
        protocol: https,
        ssl:
          { key: "./ssl/localhost-key.pem", cert: "./ssl/localhost-cert.crt" },
      }
    - { port: 1236, protocol: net } #创建一个tcp请求

注解说明

EnableServer 作用于应用上 用于开启server组件

更多用法

参考项目git地址 @fastcar/server/test 下的example内

项目开源地址