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

qcloud-weapp-server-sdk-trac

v0.8.6

Published

Wafer 服务端 SDK - Node.js trac定制加入自定义SEssion缓存

Downloads

3

Readme

Wafer 服务端 SDK - Node.js

NPM Version Minimum Node.js Version Build Status Coverage Status License

本项目是 Wafer 组成部分,以 SDK 的形式为业务服务器提供以下服务:

安装

npm install qcloud-weapp-server-sdk --save

API

参见 API 文档

使用

初始化 SDK 配置项

const qcloud = require('qcloud-weapp-server-sdk');

qcloud.config({
    ServerHost: '业务服务器的主机名',
    AuthServerUrl: '鉴权服务器地址',
    TunnelServerUrl: '信道服务器地址',
    TunnelSignatureKey: '和信道服务器通信的签名密钥',
});

使用会话服务

处理用户登录请求

业务服务器提供一个路由(如 /login)处理客户端的登录请求,直接使用 SDK 的 LoginService::login() 方法即可完成登录处理。登录成功后,可以获取用户信息。

const express = require('express');
const LoginService = require('qcloud-weapp-server-sdk').LoginService;
const app = express();

app.get('/login', (req, res) => {
    const loginService = new LoginService(req, res);

    loginService.login().then(result => {
        console.log('微信用户信息', result.userInfo);
    });
});

app.listen(80);

检查请求登录态

客户端交给业务服务器的请求,业务服务器可以通过 SDK 的 LoginService::check() 方法来检查该请求是否包含合法的会话。如果包含,则会返回会话对应的用户信息。

const express = require('express');
const LoginService = require('qcloud-weapp-server-sdk').LoginService;
const app = express();

// 获取用户信息
app.get('/user', (req, res) => {
    const loginService = new LoginService(req, res);

    loginService.check().then(result => {
        res.json({
            'code': 0,
            'message': 'ok',
            'data': {
                'userInfo': result.userInfo,
            },
        });
    });
});

app.listen(80);

阅读 Wafer Wiki 文档中的会话服务了解更多关于会话服务的技术资料。

使用信道服务

业务在一个路由上(如 /tunnel)提供信道服务,只需把该路由上的请求都交给 SDK 的信道服务处理即可。

const express = require('express');
const bodyParser = require('body-parser');
const TunnelService = require('qcloud-weapp-server-sdk').TunnelService;
const app = express();

class TunnelHandler {
    // TODO: 处理 onRequest 事件,
    onRequest(tunnelId, userInfo) {}

    // TODO: 处理 onConnect 事件
    onConnect(tunnelId) {}

    // TODO: 处理 onMessage 事件
    onMessage(tunnelId, type, content) {}

    // TODO: 处理 onClose 事件
    onClose(tunnelId) {}
}

// parse `application/json`
app.use(bodyParser.json());

// 处理信道请求
// 信道需同时处理 `GET` 和 `POST` 请求,为了方便这里使用 `all` 方法
app.all('/tunnel', (req, res) => {
    const tunnelService = new TunnelService(req, res);
    const handler = new TunnelHandler();

    tunnelService.handle(handler, { 'checkLogin': true });
});

app.listen(80);

使用信道服务需要实现处理器,来获取处理信道的各种事件,具体可参考配套 Demo 中的 ChatTunnelHandler 的实现。

阅读 Wafer Wiki 中的信道服务了解更多解决方案中关于信道服务的技术资料。

详细示例

参见项目:Wafer 服务端 DEMO - Node.js

LICENSE

MIT