-
Notifications
You must be signed in to change notification settings - Fork 37
/
casimir.js
60 lines (50 loc) · 2 KB
/
casimir.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
56
57
58
59
60
var path = require('path')
var express = require('express')
var ospath = require('ospath')
var fs = require('fs')
var ini = require('iniparser')
var casimirCore = require('casimircore')()
var properties = require(path.join(__dirname, 'config/index.js'))()
// normalize paths
properties.server.favicon = path.join(__dirname, properties.server.favicon)
properties.engine.view_folder = path.join(__dirname, properties.engine.view_folder)
properties.engine.static_folder = path.join(__dirname, properties.engine.static_folder)
// full node properties
properties.fullNodeAutoRun = typeof properties.fullNodeAutoRun === 'undefined' || properties.fullNodeAutoRun === 'true'
if (!properties.fullNodeAutoRun) {
if (!properties.fullNodeRemoteUrl) {
throw new Error('Must have "fullNodeRemoteUrl" if "fullNodeAutoRun" is false')
}
} else {
// full-node should be run and hosted locally
var fullNodePropertiesFilePath = path.join(ospath.data(), 'coloredcoins-full-node', 'properties.conf')
if (!fs.existsSync(fullNodePropertiesFilePath)) {
fullNodePropertiesFilePath = path.join(__dirname, 'node_modules/coloredcoins-full-node/properties.conf')
}
properties.fullNode = ini.parseSync(fullNodePropertiesFilePath)
}
var logSettings = {
env: properties.ENV.type,
log_dir: path.join(__dirname, 'app/log')
}
var logger = global.logger = casimirCore.logger(logSettings)
console.log = logger.info
console.error = logger.error
console.warn = logger.warn
var router = casimirCore.router(path.join(__dirname, 'routes'), path.join(__dirname, 'app/controllers'))
router.use('/js', express.static(path.join(__dirname, 'node_modules')))
router.use('/css', express.static(path.join(__dirname, 'node_modules')))
// Add custom framwork modules for server
properties.modules = {
router: router,
logger: logger,
error: casimirCore.error(properties.ENV.type)
}
// Set server and server port
var server = casimirCore.server(properties)
var casimir = {
server: server,
logger: logger,
properties: properties
}
module.exports = casimir