Socket
Socket
Sign inDemoInstall

@fangxq/request

Package Overview
Dependencies
82
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.30 to 0.0.31

6

call.d.ts

@@ -1,5 +0,1 @@

// import { TReq,TRes } from './shared';
export type TClientResultWrapper = { data?: any, ws?: WebSocket }
export async function call(target: string, req: any): Promise<TClientResultWrapper>
export async function call(target: string, req: any): Promise<any>

@@ -30,11 +30,3 @@ const axios = require('axios')

if (ret.data._wsToken) {
var WebSock = global.WebSocket || global.MozWebSocket || require('ws');
ret.data._ws = new WebSock(target + '?ws_token=' + ret.data.ws_token)
return { ws }
} else {
return { data: ret.data }
}
return ret.data
}

@@ -1,7 +0,1 @@

// import { TReq,TRes } from './shared';
export type THostResultWrapper = { data?: any, use_ws?: (ws: WebSocket) => Promise<void> }
export type Thandler = (src: string, req: any, res: THostResultWrapper) => Promise<void>;
export async function listen(host: string, port: number, handler: Thandler): Promise<import('https').Server>
export async function listen(host: string, port: number, handler: (req: any) => Promise<any>): Promise<import('https').Server>
const fs = require('fs')
const express = require('express')
// const expressWs = require('express-ws')
const https = require('https')
const cors = require('cors')
const rawbody = require('raw-body')
const { v4: uuid } = require('uuid')

@@ -20,4 +18,2 @@ function formatter(_key, value) {

const streamMap = {}
module.exports.listen = async function (host, port, handler) {

@@ -32,51 +28,10 @@ const app = express()

const src = req.headers['x-forwarded-for'] || req.socket.remoteAddress
if (!data.ip) data.ip = req.headers['x-forwarded-for'] || req.socket.remoteAddress
const result = {}
let result = await handler(data)
await handler(src, data, result)
if (result.use_ws) {
const ws_token = uuid()
const use_ws = result.use_ws
delete result.use_ws
result._wsToken = ws_token
}
// if (result.stream) {
// const stream = result.stream
// const ws_token = uuid()
// const timeout = setTimeout(() => {
// const cache = streamMap[ws_token]
// if (cache) {
// delete streamMap[ws_token]
// streamMap[ws_token].stream.close()
// }
// }, 10000)
// streamMap[ws_token] = { timeout, stream }
// delete result.stream
// result.ws_token = ws_token
// }
res.send(JSON.stringify(result))
})
// expressWs(app)
// app.ws('/', function (ws, req) {
// const ws_token = req.query.ws_token
// const cache = streamMap[ws_token]
// if (cache) {
// ws.pipe()
// } else {
// }
// })
return await new Promise((resolve => {
const server = await new Promise((resolve => {
const svr = https.createServer({

@@ -92,2 +47,4 @@ key: fs.readFileSync('./key.pem'),

}))
return server
}

2

package.json
{
"name": "@fangxq/request",
"version": "0.0.30",
"version": "0.0.31",
"description": "",

@@ -5,0 +5,0 @@ "scripts": {

@@ -1,17 +0,17 @@

// export type TReq = {
// token?: string,
export type TReq = {
token?: string,
// module: string,
// api: string,
// args: any[],
module: string,
api: string,
args: any[],
// ip?: string,
// entry?: string
// }
ip?: string,
entry?: string
}
// export type TRes = {
// result: "success" | "need_login" | "no_permission" | "invalid_token" | "error"
// data: any
// token?: string
// on_ws?: ReadableStream
// }
export type TRes = {
result: "success" | "need_login" | "no_permission" | "invalid_token" | "error"
data: any
token?: string
on_ws?: ReadableStream
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc