forked from javmorsol/sample-faq-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.js
More file actions
65 lines (49 loc) · 1.34 KB
/
Copy pathconfig.js
File metadata and controls
65 lines (49 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const environment = require('./environment');
const mongoose = require('mongoose');
const mongoosastic = require('mongoosastic');
const elasticsearch = require('elasticsearch');
const Q = require('q');
//
// elastic search
const elasticSearchClient = new elasticsearch.Client(getElasticSearchConfig());
//
// mongodb
mongoose.Promise = require('q').Promise;
mongoose.connect(getMongoUri());
const Schema = mongoose.Schema;
const topicSchema = new Schema({
title: {type: String, required: true},
items: [
{
question: {type: String, required: true},
answer: {type: String, required: true}
}
]
}, {collection: 'topics'});
//
// link
topicSchema.plugin(mongoosastic, {
esClient: elasticSearchClient
});
const topicRepository = mongoose.model('topic', topicSchema);
//
// urls
function getMongoUri() {
return `mongodb://${environment.mongodb.host}:${environment.mongodb.port}/${environment.mongodb.databaseName}`;
}
function getElasticSearchConfig() {
return {
host: environment.elasticsearch.host + ":" + environment.elasticsearch.port,
log: environment.elasticsearch.log
};
}
//
// exports
module.exports = {
getTopicRepository: function () {
return topicRepository;
},
getElasticSearchClient: function () {
return elasticSearchClient;
}
};