Commit f604147c authored by A. Koch's avatar A. Koch

updated resources and acl stuff

parent e99679cf
const
path = require('path'),
fs = require('mz/fs'),
{ MongoDB } = require('mbjs-persistence'),
{ ObjectUtil } = require('mbjs-utils'),
config = require('config')
const folder = process.env.FOLDER
if (!folder) throw new Error('no input folder specified')
const proc = async function (folder) {
const mapsClient = new MongoDB(
ObjectUtil.merge({ name: 'maps', logger: console },
config.get('resources.mongodb')),
'uuid'
)
await mapsClient.connect()
const maps = await fs.readdir(path.join(folder, 'maps'))
for (let m of maps) {
const file = await fs.readFile(path.join(folder, 'maps', m))
const entry = JSON.parse(file)
await mapsClient.create(entry)
}
const annoClient = new MongoDB(
ObjectUtil.merge({ name: 'annotations', logger: console },
config.get('resources.mongodb')),
'uuid'
)
await annoClient.connect()
const annos = await fs.readdir(path.join(folder, 'annotations'))
for (let a of annos) {
const file = await fs.readFile(path.join(folder, 'annotations', a))
const entry = JSON.parse(file)
await annoClient.create(entry)
}
}
proc(folder)
.then(() => process.exit(0))
......@@ -339,6 +339,11 @@
"color-convert": "^1.9.0"
}
},
"any-promise": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/any-promise/-/any-promise-1.3.0.tgz",
"integrity": "sha1-q8av7tzqUugJzcA3au0845Y10X8="
},
"argparse": {
"version": "1.0.10",
"resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz",
......@@ -2253,6 +2258,16 @@
"integrity": "sha1-MHXOk7whuPq0PhvE2n6BFe0ee6s=",
"dev": true
},
"mz": {
"version": "2.7.0",
"resolved": "https://registry.npmjs.org/mz/-/mz-2.7.0.tgz",
"integrity": "sha512-z81GNO7nnYMEhrGh9LeymoE4+Yr0Wn5McHIZMK5cfQCl+NDX08sCZgUc9/6MHni9IWuFLm1Z3HTCXu2z9fN62Q==",
"requires": {
"any-promise": "^1.0.0",
"object-assign": "^4.0.1",
"thenify-all": "^1.0.0"
}
},
"nan": {
"version": "2.10.0",
"resolved": "https://registry.npmjs.org/nan/-/nan-2.10.0.tgz",
......@@ -3095,6 +3110,22 @@
"integrity": "sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=",
"dev": true
},
"thenify": {
"version": "3.3.0",
"resolved": "https://registry.npmjs.org/thenify/-/thenify-3.3.0.tgz",
"integrity": "sha1-5p44obq+lpsBCCB5eLn2K4hgSDk=",
"requires": {
"any-promise": "^1.0.0"
}
},
"thenify-all": {
"version": "1.6.0",
"resolved": "https://registry.npmjs.org/thenify-all/-/thenify-all-1.6.0.tgz",
"integrity": "sha1-GhkY1ALY/D+Y+/I02wvMjMEOlyY=",
"requires": {
"thenify": ">= 3.1.0 < 4"
}
},
"through": {
"version": "2.3.8",
"resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz",
......
......@@ -40,6 +40,7 @@
"mbjs-utils": "0.0.5",
"mongodb": "^3.1.0",
"morgan": "^1.9.0",
"mz": "^2.7.0",
"nedb": "^1.8.0",
"polka": "^0.4.0",
"primus": "^7.2.2",
......
......@@ -6,6 +6,7 @@ const
const setupACL = async function (app) {
const cfg = config.get('acl.mongodb')
cfg.logger = console
const client = new MongoDB(cfg, 'uuid')
await client.connect()
const acl = new Acl(new Backend(client.db, cfg.prefix))
......
......@@ -75,7 +75,11 @@ const setup = async function () {
/**
* Start server
*/
app.listen(port, host).then(() => winston.log('info', `API started on ${host}:${port}`))
return app.listen(port, host).then(() => winston.log('info', `API started on ${host}:${port}`))
}
setup()
setup().catch(err => {
process.stderr.write(err.message + '\n')
process.stderr.write(err.stack + '\n')
process.exit(err.code)
})
......@@ -19,7 +19,7 @@ class Service extends TinyEmitter {
app.get(`/${this._name}`, async (req, res) => {
const results = await this.client.find(req.params.query || {}, req.params)
_this._response(req, res, results)
_this._response(req, res, { items: results })
})
app.get(`/${this._name}/:id`, async (req, res) => {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment