CODE
1 year ago
7 changed files with 145 additions and 53 deletions
@ -0,0 +1,55 @@ |
|||
'use strict'; |
|||
const fs = require('fs'); |
|||
const path = require('path'); |
|||
const es = require('elasticsearch'); |
|||
|
|||
let initClient = (config, opts) => { |
|||
|
|||
let logOptions; |
|||
if (opts.dev) { |
|||
let filename = path.join(process.cwd(), 'log', 'elasticsearch-development.log'); |
|||
let dir = path.dirname(filename); |
|||
if (!fs.existsSync(dir)) { |
|||
fs.mkdirSync(dir); |
|||
} |
|||
logOptions = { |
|||
type: 'file', |
|||
level: 'info', |
|||
path: filename |
|||
}; |
|||
} else { |
|||
logOptions = { |
|||
type: 'stdio', |
|||
level: 'error' |
|||
}; |
|||
} |
|||
let client = new es.Client({ |
|||
host: config.rootURL, |
|||
log: logOptions, |
|||
apiVersion: '5.5' |
|||
}); |
|||
return client; |
|||
}; |
|||
|
|||
function factory (app, opts) { |
|||
if (opts.es) { |
|||
try { |
|||
app.fs.esclient = {} |
|||
let esclient = Object.keys(opts.es).reduce((p, esmodule) => { |
|||
console.log(`加载 ES ${esmodule}`); |
|||
let moduleCfg = opts.es[esmodule]; |
|||
let client = initClient(moduleCfg, opts); |
|||
p[esmodule] = client; |
|||
p[esmodule].config = moduleCfg; |
|||
return p; |
|||
}, {}); |
|||
|
|||
app.fs.esclient = esclient; |
|||
} catch (error) { |
|||
console.error(error) |
|||
process.exit(-1); |
|||
} |
|||
} |
|||
} |
|||
|
|||
module.exports = factory; |
@ -1,44 +1,45 @@ |
|||
{ |
|||
"name": "smart-emergency", |
|||
"version": "1.0.0", |
|||
"description": "fs smart emergency api", |
|||
"main": "server.js", |
|||
"scripts": { |
|||
"test": "set DEBUG=true&&\"node_modules/.bin/mocha\" --harmony --reporter spec app/test/*.test.js", |
|||
"start": "set NODE_ENV=development&&node server -p 4000 -g postgres://postgres:123@10.8.30.32:5432/video_access -f http://localhost:4000", |
|||
"start:linux": "export NODE_ENV=development&&node server -p 4000 -g postgres://FashionAdmin:123456@10.8.30.39:5432/pm1", |
|||
"automate": "sequelize-automate -c sequelize-automate.config.js" |
|||
}, |
|||
"author": "", |
|||
"license": "MIT", |
|||
"repository": {}, |
|||
"dependencies": { |
|||
"@alicloud/pop-core": "^1.7.12", |
|||
"@fs/attachment": "^1.0.0", |
|||
"args": "^3.0.7", |
|||
"better-xlsx": "^0.7.6", |
|||
"clickhouse": "^2.6.0", |
|||
"crypto-js": "^4.0.0", |
|||
"file-saver": "^2.0.2", |
|||
"fs-web-server-scaffold": "^2.0.2", |
|||
"ioredis": "^5.0.4", |
|||
"kafka-node": "^5.0.0", |
|||
"koa-convert": "^1.2.0", |
|||
"koa-proxy": "^0.9.0", |
|||
"moment": "^2.24.0", |
|||
"mqtt": "^4.3.7", |
|||
"node-schedule": "^2.1.0", |
|||
"nodemailer": "^6.7.7", |
|||
"path": "^0.12.7", |
|||
"path-to-regexp": "^3.0.0", |
|||
"pg": "^7.9.0", |
|||
"redis": "^3.1.2", |
|||
"request": "^2.88.2", |
|||
"sequelize-automate-freesun": "^1.2.2", |
|||
"superagent": "^3.5.2", |
|||
"uuid": "^3.3.2" |
|||
}, |
|||
"devDependencies": { |
|||
"mocha": "^6.0.2" |
|||
} |
|||
"name": "smart-emergency", |
|||
"version": "1.0.0", |
|||
"description": "fs smart emergency api", |
|||
"main": "server.js", |
|||
"scripts": { |
|||
"test": "set DEBUG=true&&\"node_modules/.bin/mocha\" --harmony --reporter spec app/test/*.test.js", |
|||
"start": "set NODE_ENV=development&&node server -p 4000 -g postgres://postgres:123@10.8.30.32:5432/video_access -f http://localhost:4000", |
|||
"start:linux": "export NODE_ENV=development&&node server -p 4000 -g postgres://FashionAdmin:123456@10.8.30.39:5432/pm1", |
|||
"automate": "sequelize-automate -c sequelize-automate.config.js" |
|||
}, |
|||
"author": "", |
|||
"license": "MIT", |
|||
"repository": {}, |
|||
"dependencies": { |
|||
"@alicloud/pop-core": "^1.7.12", |
|||
"@fs/attachment": "^1.0.0", |
|||
"args": "^3.0.7", |
|||
"better-xlsx": "^0.7.6", |
|||
"clickhouse": "^2.6.0", |
|||
"crypto-js": "^4.0.0", |
|||
"elasticsearch": "^13.3.1", |
|||
"file-saver": "^2.0.2", |
|||
"fs-web-server-scaffold": "^2.0.2", |
|||
"ioredis": "^5.0.4", |
|||
"kafka-node": "^5.0.0", |
|||
"koa-convert": "^1.2.0", |
|||
"koa-proxy": "^0.9.0", |
|||
"moment": "^2.24.0", |
|||
"mqtt": "^4.3.7", |
|||
"node-schedule": "^2.1.0", |
|||
"nodemailer": "^6.7.7", |
|||
"path": "^0.12.7", |
|||
"path-to-regexp": "^3.0.0", |
|||
"pg": "^7.9.0", |
|||
"redis": "^3.1.2", |
|||
"request": "^2.88.2", |
|||
"sequelize-automate-freesun": "^1.2.2", |
|||
"superagent": "^3.5.2", |
|||
"uuid": "^3.3.2" |
|||
}, |
|||
"devDependencies": { |
|||
"mocha": "^6.0.2" |
|||
} |
|||
} |
|||
|
Loading…
Reference in new issue