🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

wps-airscript-router

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wps-airscript-router

一个简单的WPS AirScript应用框架,尤其适用于Webhook调用场景。

latest
Source
npmnpm
Version
1.0.4
Version published
Weekly downloads
9
-40%
Maintainers
1
Weekly downloads
 
Created
Source

wps-airscript-router

WPS AirScript路由应用框架,适用于复杂的webhook调用。

process

搭配Node环境使用

npm install --save wps-airscript-router
import AppFactory from 'wps-airscript-router'

// 统一配置路由
const app = AppFactory.createApp([
    { path: 'index', handle: () => 'index response' }
])

// 单独新增路由
app.route('test', () => 'test response')

// 配置默认处理
app.setDefaultHandle(() => 404)

// 配置错误处理
app.setErrorHandle((_error: any) => 500)

const bootstrap = () => {
    const { method } = Context.argv;
    const handle = app.getHandle(method);
    return handle();
}

export default bootstrap()

直接在AirScript中使用

  • 将dist/browser/index.js中的代码复制到airscript脚本编辑器第一行
  • 新增以下代码
const app = AppFactory.createApp()

// 定义一条路由
app.route('index', () => 'index response')

// path是http调用webhook时传入的body参数
const { path } = Context.argv;
const handle = app.getHandle(path);

// return保证http调用webhook有返回值
return handle();

Keywords

wps

FAQs

Package last updated on 21 Mar 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts