fkc
Version:
FKC application service framework.
47 lines • 1.28 kB
JavaScript
;
let obj = { host: {} };
function config(d) {
obj = { ...obj, ...d }
if (!obj.err) {
//开启服务
if (obj.cluster) {
// 开启集群
require('./cluster')(obj);
} else {
require('./server')(obj);
}
} else {
console.log(obj.err);
}
}
function addHost(web, ssl) {
const error = require('../json/error');
const { repAll } = require('../util');
const Router = require('./router');
const { str, obj: objs } = require('../type');
if (!web) web = '*';
if (!str(web)) {
obj.err = error.host[0];
} else {
let ovj = { path: {} };
if (ssl) {
if (!objs(ssl)) {
obj.err = error.ssl;
} else {
if (!ssl.key || !ssl.cert) {
obj.err = error.ssl;
} else {
ovj.ssl = ssl;
}
}
}
if (web !== '*' && web.includes('*')) {
web = repAll('*', web);
if (!obj.reg) obj.reg = [];
obj.reg.push(web);
}
obj.host[web] = ovj;
}
return Router(obj, web);
}
module.exports = { config, host: addHost }