1.5.7 • Published 5 years ago
njserver v1.5.7
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: '123456'
}
},
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 //每个进程单独记录日志
}
};
1.5.7
5 years ago
1.5.6
5 years ago
1.5.5
5 years ago
1.5.4
5 years ago
1.5.3
5 years ago
1.5.2
5 years ago
1.5.1
5 years ago
1.5.0
5 years ago
1.4.13
5 years ago
1.4.12
5 years ago
1.4.11
5 years ago
1.4.10
5 years ago
1.4.9
5 years ago
1.4.8
5 years ago
1.4.7
5 years ago
1.4.6
5 years ago
1.4.5
5 years ago
1.4.3
5 years ago
1.4.2
5 years ago
1.4.1
5 years ago
1.4.0
5 years ago
1.3.17
5 years ago
1.3.16
5 years ago
1.3.15
5 years ago
1.3.14
5 years ago
1.3.13
5 years ago
1.3.12
5 years ago
1.3.11
5 years ago
1.3.10
5 years ago
1.3.9
5 years ago
1.3.8
5 years ago
1.3.7
5 years ago
1.3.6
5 years ago
1.3.5
5 years ago
1.3.4
5 years ago
1.3.3
5 years ago
1.3.2
5 years ago
1.3.0
5 years ago
1.2.12
5 years ago
1.2.11
5 years ago
1.2.10
5 years ago
1.2.9
5 years ago
1.2.8
5 years ago
1.2.7
5 years ago
1.2.6
5 years ago
1.2.3
5 years ago
1.2.2
5 years ago
1.2.1
5 years ago
1.2.0
5 years ago
1.0.6
5 years ago
1.0.5
5 years ago
1.0.4
5 years ago
1.0.3
5 years ago
1.0.2
5 years ago
1.0.1
5 years ago
1.0.0
5 years ago