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

fworkcloud

v1.0.9

Published

基于express框架封装多站点web服务支持https协议

Downloads

5

Readme

基于express框架封装多站点web服务 支持https协议

1.使用插件

const fworkCloud = require('fworkCloud');
new fworkCloud('htdocs');//为项目下的子目录文件夹名称 默认目录为htdocs

2.项目结构

'htdocs'为项目下的子目录文件夹名称,可存放多个站点  
'htdocs'目录下有config.js配置文件和多个站点目录
假设项目文件夹路径为  D:\nodejs\demo\htdocs   
配置文件位置 D:\nodejs\demo\htdocs\config.js   
测试站点A目录为cloudA 则站点项目路径为 D:\nodejs\demo\htdocs\cloudA
测试站点A路由路径为 D:\nodejs\demo\htdocs\cloudA\router.js
站点目录cloudA下有两个子目录名为ssl(存放站点http协议证书)和page(存放站点路由文件) 
证书文件路径  D:\nodejs\demo\htdocs\cloudA\ssl\** server.crt server.key server.pem

config.js配置文件代码如下

站点配置如下

| 参数名 | 类型 | 参数值 | 必填 | 说明 | | :-------------| :----------: | ------------: | ------------: | ------------: | | http | Boolean或string | false/true | 否 | 开启http协议 默认true | | https | Boolean或string | false/true | 否 | 开启https协议 默认true | | name | string | CloudBase | 否 | 站点名称 | | path | string | cloudC | | 站点目录 | | use | array | ['mongo'] | 否 | 插件集合 mongo为插件名 | | static | string | public | 否 | 站点目录下 | | type | string | h5或者H5 | 否 | h5模式 静态站点 | | index | string | xxx.html | 否 | 设置静态首页 | | copy | string | 192.168.0.108 | 否 | 映射站点192.168.0.108项目 ||||||

var config = {
    http:8080,
    https:443,
    web:{
        '192.168.0.100':{               //192.168.0.100为主机名 可为ip或者域名
            http: false,                // false 关闭http协议 默认为true开启
            https: true,                //如果开启https协议 需要添加ssl证书 
            use: ['mongo'],             //插件 类似express中间件 mongo为插件名
                                          D:\nodejs\demo\htdocs\cloudA\use.js
            name: '测试站点A',           //站点标题
            path: 'cloudA',             //站点目录 D:\nodejs\demo\htdocs\cloudA
            static: 'public',           //静态目录 D:\nodejs\demo\htdocs\public
            upload: 'upload'            //上传目录 D:\nodejs\demo\htdocs\upload
        },
        'localhost':{ 
            //默认开启http和https协议
            name: 'CloudBase',
            path: 'cloudB',
            type: 'h5',                 //type=h5或者H5 时,cloudB为h5静态站点 默认首页为index.html
            index: 'xxx.html',          //设置首页为xxx.html
        },
        '192.168.0.108':{
            name: 'CloudBase',
            path: 'cloudC',        
            copy: '192.168.0.100'       //映射192.168.0.100项目  
                                        //有https需要在cloudC/ssl目录下添加 
        }
    }
}
module.exports = config;

站点路由配置文件router.js代码如下

const router = {
    '/add': {
        name:'添加',
        path:'add'
    },
    '/remove': {
        name:'删除',
        path:'remove'
    },
    '/update': {
        name:'更新',
        path:'update'
    },
    '/where': {
        name:'查询',
        path:'where'
    },
    '/get': {
        name:'查询',
        path:'get'
    },
    '/list': {
        name:'测试',
        path:'list'
    }
}
module.exports = router

站点路由文件代码如下

'use strict';
exports.main = async (event,context) => {
    //upload方法代码如下 Promise对象
    const obj={ // obj可为空
        type:['jpg'],//限制文件类型
        size:1,      //限制文件大小单位1m
        orig:true,   //orig为true时 上传文件适用原始文件名
        add:{userid:1233655} //插入字段
    }
    const fileList = await context.upload('20220801',obj)
    //20220801上传目录,可为空 在上传根目录upload下 支持多级例如2022/08/01
    const db = context.use.mongo //调用use插件mongo
    const data = {
        "key1": "test1",
        "key2": "test2"
    }
    const rest = await db.add('test',data) //添加mongodb数据
    return rest
};
//context 为客户端请求信息 context.use为封装插件集合 
//context.use.mongo为mongoDB数据库封装 https://www.npmjs.com/package/fworkmongo
//event 为请求体整合对象{} query和body合并  属性相同body会覆盖 query

use下的mongo插件代码如下 可返回Promise

'use strict';
async function db() {
    const db = require('fworkmongo');
    const conf = {
        connect: 'mongodb://127.0.0.1:27017/',
        model: {
            test: {
                key1: 'String',
                key2: 'String'
            }
        }
    }
    await db.connect(conf)
    return new Promise((resolve) => {
        resolve(db)
    })
}
module.exports = db()