1.0.18 • Published 3 months ago

run_func_serve v1.0.18

Weekly downloads
-
License
ISC
Repository
-
Last release
3 months ago

run_func_serve

用于在服务端运行前端传来的函数, 可用于操作MongoDB数据库以及处理文件上传等

init

var rfs = require('run_func_serve')

// 初始化
// 设置默认的数据库名, 默认为 base
// 以及一个可以通过名称得到对应数据库的 async 方法
rfs.init({
	db_name: 'base',
	getDB: null
})

// 通过接口调用
route.post('/func', async (req, res) => {
	await rfs.run_func(req, res)
})

在前端使用

前端引入 run_func_client.js

import rfc from "run_func_serve/run_func_client";


// 初始化, 默认值: 'http://localhost:3002'
func.init({server: '', db_name: 'base'})

// 远程运行, 处理数据库(MongoDB)
func.run(async db => {
    return await db.collection('users')
        .find({}, {projection: {_id: 0})
        .toArray()
}).then(find_res = {
    console.log('rfc find result:', find_res)
})

// 其它形式, 支持队列及参数数组
func.run('queue', async db => {})
func.run([param1, param2, ...], async db => {})
func.run('queue', [param1, param2, ...], async db => {})

// 文件上传, 支持多文件上传, files: fileList.files
func.upload(files).then()

注意: 如果前端进行代码压缩, 需要保留 db 字段

1.0.6版本之后, 不再需要设置 mangle.reserved

terser({
	compress: {
		// drop_console: true
	},
	mangle: {
		reserved: [
			'db' 		// db, prom for run_func_serve
		]
	}
}
1.0.18

3 months ago

1.0.17

6 months ago

1.0.16

6 months ago

1.0.15

6 months ago

1.0.14

6 months ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago