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

wind-boot

v1.0.3

Published

Boot loader for a koa-based modularized application booter

Downloads

14

Readme

wind-boot

基于koa web框架的模块化应用加载器

基本用法

在服务端应用中,一个应用会包含多个模块,包括底层模块、通用功能模块、通用业务模块、业务模块等。 从开发和验证角度,各种模块应该能被独立开发、测试、验证及替换(功能),从业务整合角度,这些模块又需要能被自由组合、包装成一个个具体应用。 要满足以上要求需要一个最小化的服务加载框架,基于koa的洋葱圈开发模型将各个模块组合到一起

加载框架的职责就是加载、初始化每个模块。而各个模块都是独立的,排除一些公共依赖可以进行独立部署。

HTTP相关配置

const config = {
    port: 8082,  // http服务端口, 不写则不提供http服务
    proxy: {     // 代理服务,带服务则
        '/portal': {
            target: 'https://10.10.2.68:8102',
            secure: false
        },
        '/api': {
            target: 'http://10.10.247.1:4877'
        }
    },
    httpsPort: 4099,  // https服务端口, port/key/cert 必须都提供才能提供https服务
    httpsKey: './key/server.key',
    httpsCert: './key/server.crt'
}

基本模块化挂载

const module1 = {
    created (app) {
      app.created = true
    },
    ready (app) {
      app.ready = true
    },
    bootComplete (app) {
      app.bootfin = true
    }
  }
  const config = {
    debug: 'wind:boot',
    packages: [module1]
  }
  const boot = new BootStrap(config)
  await boot.start()

  expect(boot.app.created).toBe(true)
  expect(boot.app.ready).toBe(true)
  expect(boot.app.bootfin).toBe(true)

  await boot.stop()

加载器流程

  1. created: 模块进行依次加载并依次调用模块的created方法,主要是工作是系统类模块进行koa插件注册、业务模块进行对外服务初始化并挂载到app上
  2. auto-wire: 框架基于上一步骤对业务模块的对外服务进行自动注入(基于字段名称和服务类名的匹配)
  3. ready: 业务模块初始化路由、controller、服务手动注入(不依赖auto-wire)
  4. completed: 路由插件注册、koa其他内层插件注册、服务初始化(数据建表、索引、建缓存等)

模块规约

模块下要求有一个index.js文件,用于定义模块的服务及依赖、初始化等工作,按照上述流程,其模式如下

module.exports = {
  name: 'moduleName',
  description: '模块名称',
  
  // 模块初始化动作,对于核心模块可以进行koa相关插件注册
  // 业务模块可以进行服务创建
  async created (app) {
    // 例如 app.context.moduleService = new ModuleService()
  },
  
  // 模块路由注册,对外提供API可在此写api相关地址
  async ready (app) {
    // 示例  
    // const router = app.context.router
    // router.get('/flaticon/search', async (ctx, next) => {
    //    ctx.moduleService.hello()
    // })
  },
  
  // 启动收尾工作,可以在此执行建库、建索引等一些全局的具体业务操作
  async bootComplete (app) {
    
  }
}