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

bst-node-apollo

v1.0.14

Published

node请求携程Apollo配置

Downloads

3

Readme

BST-NODE-APOLLO

初始化

    npm install bst-node-apollo -S

在node的服务启动文件内引入Apollo

    const {init,getConfig}=require('bst-node-apollo');
    ...
    ...
    /*
        需要在使用Apollo配置的模块引入之前执行init:
        init函数可以传入具体的配置项参数,文档地址
    */
    (async function(){
        await init({
            configServerUrl:"Apollo地址",//这项如果不传则取环境变量值,具体情况查看文档
            appId:"Apollo对应项目的appid",
            namespaceName:["test.json"],//该项目下你想拉取的配置文件(请注意、配置文件需以:“node-”开头,如果没有此字段,默认会加上此前缀,)
        });
        const {port,appConfig}=getConfig()
        var app = require('../app');
        server = http.createServer(app.callback());
        server.listen(port||3000);
        server.on('error', onError);
        server.on('listening', onListening);
    }())

其他模块引入

    //在需要使用config的模块引入
    const {getConfig}=require('bst-node-apollo');

    let PORT=getConfig('port');
    ...
    ...

健康检查 //在koa2或者express框架下的app.js内添加use

    
    ...
    const {lifeCheck}=require('bst-node-apollo');
    //尽力在第一个app.use()前添加
    app.use(lifeCheck(/*'koa'或者'express'*/))
    
    ...
    ...

方法描述

function | parameter(type) | return(type) |explain ---|---|---|--- init |options(Object)|Promise|用于初始化请求Apollo服务器的配置:内含(appId、namespaceName)必传项;namespaceName必须为数组、内含Apollo上的配置文件名,例如(namespaceName:["component-wechart.json","node-server.json"])configServerUrl为请求Apollo的地址,缺省则默认取process.env.APOLLO_ADDR的值;clusterName默认取process.env.APOLLO_IDC或者'default';apolloEnv默认取process.env.APOLLO_ENV或者'dev'; getConfig |configKey(String)|configData|用于各模块获取配置;不传入参数时返回所有拉取后的配置项 lifeCheck |frameName(String)|function|用于docker的健康检查连接,frameName可选值有:koa/express/空,三种(如果是node默认http/https启动服务则不传),请根据当前node使用服务框架传值,服务启动成功后访问当前地址下路径/node/lifecheck进行验证

具体详情参考 https://github.com/Quinton/node-apollo 中remoteConfigServiceSkipCache文档