forked from itemsapi/itemsapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
55 lines (46 loc) · 2.24 KB
/
app.js
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
'use strict';
var itemsapi = require('./server');
var config = require('./config/index').get()
var logger = require('./config/logger')
var colors = require('colors')
//var figlet = require('figlet')
var statusHelper = require('./src/helpers/status');
//console.log(figlet.textSync('itemsapi'))
console.log('Welcome to ItemsAPI'.green);
console.log('Ideas, issues or questions - https://github.com/itemsapi/itemsapi/issues')
console.log()
itemsapi.init({
elasticsearch: config.elasticsearch
})
itemsapi.start(function serverStart(serverInstance) {
var host = serverInstance.address().address;
var port = serverInstance.address().port;
if (!host || host === '::') {
host = '127.0.0.1'
}
return statusHelper.elasticsearch(config.elasticsearch.host)
.then(function(result) {
logger.info('ItemsAPI started!'.green)
if (result.elasticsearch_status === 200) {
if (result.version >= '2.0') {
logger.info('Your Elasticsearch version: %s is not recommended'.yellow, result.version)
logger.info('Your api might not work properly'.yellow)
logger.info('Instructions about recommended Elasticsearch version - https://github.com/itemsapi/itemsapi/blob/master/ELASTICSEARCH.md'.yellow)
} else {
logger.info('Elasticsearch status -', 'OK'.green)
}
itemsapi.get('logger').info('')
itemsapi.get('logger').info('In order for easier API management, you can: ')
itemsapi.get('logger').info('- install CLI tool `sudo npm install itemsapi-cli -g` and follow instructions')
itemsapi.get('logger').info('- install search web application with frontend and admin side. (https://github.com/itemsapi/starter)')
itemsapi.get('logger').info('')
itemsapi.get('logger').info('Your API url - http://%s:%s/api/v1'.green, host, port)
} else {
logger.info('Elasticsearch status -', config.elasticsearch.host.red + ' is unavailable.'.red)
logger.info('Your application might not work properly'.red)
logger.info('Instructions about how to run Elasticsearch - https://github.com/itemsapi/itemsapi/blob/master/ELASTICSEARCH.md'.red)
logger.info('To start app with your custom elasticsearch url:'.red)
logger.info('ELASTICSEARCH_URL=http://localhost:9200 npm start'.red)
}
})
});