1 Star 0 Fork 1

flynn / njserver

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

njserver

安装njserver

npm install njserver

njserver命令

  • 初始化项目文件:npm njserver init
  • 更新项目文件:npm njserver update
  • 启动njserver程序:npm njserver start

启动njserver

var njserver = require('njserver');

njserver.use('/', './assets/');

njserver.use('/', {
    dir: './controller/'
});

njserver.use('/', {
    before: function (req, res, next) {
        require('./interceptor/access')(req, res, next);
    },

    after: function (req, res, chunk, next) {
        require('./interceptor/content')(req, res, chunk, next);
    }
});

njserver.listen();

config.js配置文件示例

global.sysConfig = {
    serverName: 'test', //应用名称
    serverDescription: '测试系统', //应用描述
    isDebug: true, //是否调试模式
    servers: [{ //监听协议及端口
            protocol: 'http',
            port: 8081
        },
        {
            protocol: 'https',
            port: 443,
            key: '94xh.com.key',
            cert: '94xh.com.pem'
        },
        {
            protocol: 'http2',
            port: 8082,
            key: '94xh.com.key',
            cert: '94xh.com.pem'
        }
    ],
    session: {
        timeout: 1800000, //session过期时间,单位ms,默认30min
        store: 'mysql', //session存储介质,默认为空使用内存存储,可设置数据库类型:mysql
        table: 'sessions' //存储在数据库中的表名称,结构:`njsid` varchar(255) 主键 && `session` json && `update` datetime(0)
    },
    sessionClearTime: '0 */30 * * * *', //每30分钟清理一次过期session
    requestTimeout: 120000, //request请求超时时间,单位ms,默认120s
    responseTimeout: 120000, //response响应超时时间,单位ms,默认120s
    fileCacheControl: 'max-age=7200', //静态文件客户端缓存配置,默认2h过期
    page404: '', //自定义404页面路径,默认不设置为空
    page500: '', //自定义500页面路径,默认不设置为空
    mysql: { //mysql数据库连接配置
        host: '127.0.0.1', //mysql数据库主机
        user: 'root', //mysql数据库用户名
        password: '123456', //mysql数据库密码
        database: 'test', //mysql数据库名称
        supportBigNumbers: true, //处理大数字(BIGINT和DECIMAL)时需要启动此项
        bigNumberStrings: true, //使用supportbignumbers和bignumberstrings时总是返回JavaScript字符串对象
        multipleStatements: true, //mysql数据库查询是否支持多条语句
        connectionLimit: 10, //mysql连接池创建的最大连接数
        connectTimeout: 10000, //mysql连接超时时间,单位ms,默认10s
        acquireTimeout: 10000, //mysql从连接池中获取连接超时时间,单位ms,默认10s
        timeout: 60000, //mysql查询超时时间,单位ms,默认10s
        timezone: '08:00' //mysql时区设置
    },
    mssql: { //mssql数据库连接配置
        server: '127.0.0.1', //mssql数据库主机
        user: 'sa', //mssql数据库用户名
        password: '123456', //mssql数据库密码
        database: 'test', //mssql数据库名称
        connectionTimeout: 15000, //mssql连接超时时间,单位ms,默认15s
        requestTimeout: 600000, //mssql查询超时时间,单位ms,默认15s
        parseJSON: true, //将json数据集转化成json对象
        multipleStatements: true, //mssql数据库查询是否支持多条语句
        pool: {
            max: 10, //mssql连接池创建的最大连接数
            acquireTimeoutMillis: 10000, //mysql从连接池中获取连接超时时间,单位ms,默认不限制
            idleTimeoutMillis: 30000 //mssq连接池空闲连接保持时间,单位ms,默认30s
        }
    },
    tableRoute: { //数据库名称加密映射
        '0000000x': 'dw_log'
    },
    mail: {
        service: 'QQex',
        auth: {
            user: 'test@qq.com',
            pass: '12345678'
        }
    },
    mime: { //服务器支持的MIME类型
        css: 'text/css',
        gif: 'image/gif',
        html: 'text/html',
        htm: 'text/html',
        ico: 'image/x-icon',
        jpeg: 'image/jpeg',
        jpg: 'image/jpeg',
        js: 'text/javascript',
        json: 'application/json',
        pdf: 'application/pdf',
        png: 'image/png',
        svg: 'image/svg+xml',
        swf: 'application/x-shockwave-flash',
        tiff: 'image/tiff',
        txt: 'text/plain',
        woff: 'application/font-woff',
        woff2: 'application/font-woff',
        ttf: 'application/octet-stream',
        wav: 'audio/x-wav',
        wma: 'audio/x-ms-wma',
        wmv: 'video/x-ms-wmv',
        xml: 'text/xml',
        exe: 'application/octet-stream',
        docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
        doc:'application/msword',
        xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
        xls:'application/vnd.ms-excel',
        zip: 'application/zip',
        rar:' application/octet-stream',
        mp4: 'video/mp4 application/octet-stream',
        ppt:'application/vnd.ms-powerpoint',
        pptx:'application/vnd.openxmlformats-officedocument.presentationml.presentation',
        mp3:'audio/mpeg',
        bmp:'image/bmp'
    },
    uploadType: ['gif', 'jpg', 'png', 'bmp', 'xls', 'xlsx', 'doc', 'docx', 'ppt', 'pptx', 'pdf', 'zip', 'rar', 'txt'], //允许上传文件的格式
    uploadTemp: './tmp', //上传文件的临时保存路径
    uploadMaxFieldsSize: 10485760, //允许POST参数大小,单位byte,默认10mb
    uploadMaxFields: 1000, //允许POST参数数量
    uploadMaxFileSize: 104857600, //允许上传文件的大小,单位byte,默认100mb
    downloadBufferSize: 1048576, //下载文件块大小,单位byte,默认1mb
    downloadFileSize: 104857600, //允许下载文件的大小,单位byte,默认100mb
    log4js: { //日志配置
        appenders: {
            'rule-console': { //控制台打印
                type: 'console'
            },
            'rule-access': { //用户访问记录
                type: 'dateFile',
                filename: './logs/access/acc.log',
                encoding: 'utf-8',
                pattern: 'yyyy-MM-dd',
                daysToKeep: 30,
                keepFileExt: true,
                alwaysIncludePattern: true
            },
            'rule-system': { //服务器日志记录
                type: 'dateFile',
                filename: './logs/system/sys.log',
                encoding: 'utf-8',
                pattern: 'yyyy-MM-dd',
                daysToKeep: 30,
                keepFileExt: true,
                alwaysIncludePattern: true
            }
        },
        categories: {
            default: {
                appenders: ['rule-console', 'rule-system'],
                level: 'debug' //服务器日志记录级别
            },
            access: {
                'appenders': ['rule-access'],
                'level': 'info' //服务器日志记录级别
            }
        },
        pm2: true, //使用pm2启动应用
        disableClustering: true //每个进程单独记录日志
    }
};
MIT License Copyright (c) 2020 flynn Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

NodeJs Server开发框架,路由控制、全局拦截注入等特性 展开 收起
JavaScript 等 3 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
JavaScript
1
https://gitee.com/gookee/njserver.git
git@gitee.com:gookee/njserver.git
gookee
njserver
njserver
master

搜索帮助