WIP
This commit is contained in:
parent
0aa457680c
commit
47db8e9ead
7 changed files with 136 additions and 114 deletions
80
lib/app.js
80
lib/app.js
|
|
@ -2,6 +2,8 @@ const fs = require('fs')
|
|||
const http = require('http')
|
||||
const https = require('https')
|
||||
const express = require('express')
|
||||
const loop = require('reoccur')
|
||||
|
||||
const routes = require('./routes')
|
||||
const plugins = require('./plugins')
|
||||
const logger = require('./logger')
|
||||
|
|
@ -13,6 +15,20 @@ const options = require('./options')
|
|||
const devMode = argv.dev || argv.http || options.http
|
||||
|
||||
function run () {
|
||||
let count = 0
|
||||
return loop((recur, resolve, reject) => {
|
||||
return runOnce()
|
||||
.then(resolve)
|
||||
.catch(err => {
|
||||
count += 1
|
||||
logger.debug(err)
|
||||
logger.debug('[%d] Retrying in 10s...', count)
|
||||
setTimeout(recur, 10000)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function runOnce () {
|
||||
const app = express()
|
||||
const localApp = express()
|
||||
|
||||
|
|
@ -21,47 +37,45 @@ function run () {
|
|||
|
||||
return configManager.load()
|
||||
.then(config => {
|
||||
plugins.configure(config)
|
||||
plugins.startPolling()
|
||||
plugins.startCheckingNotification()
|
||||
return plugins.configure(config)
|
||||
.then(() => {
|
||||
plugins.startPolling()
|
||||
plugins.startCheckingNotification()
|
||||
|
||||
const httpsServerOptions = {
|
||||
key: fs.readFileSync(options.keyPath),
|
||||
cert: fs.readFileSync(options.certPath),
|
||||
requestCert: true
|
||||
}
|
||||
const httpsServerOptions = {
|
||||
key: fs.readFileSync(options.keyPath),
|
||||
cert: fs.readFileSync(options.certPath),
|
||||
requestCert: true
|
||||
}
|
||||
|
||||
const server = devMode
|
||||
? http.createServer(app)
|
||||
: https.createServer(httpsServerOptions, app)
|
||||
const server = devMode
|
||||
? http.createServer(app)
|
||||
: https.createServer(httpsServerOptions, app)
|
||||
|
||||
const port = 3000
|
||||
const localPort = 3030
|
||||
const localServer = http.createServer(localApp)
|
||||
const port = 3000
|
||||
const localPort = 3030
|
||||
const localServer = http.createServer(localApp)
|
||||
|
||||
if (options.devMode) logger.info('In dev mode')
|
||||
if (options.devMode) logger.info('In dev mode')
|
||||
|
||||
const opts = {
|
||||
app,
|
||||
localApp,
|
||||
devMode,
|
||||
plugins
|
||||
}
|
||||
const opts = {
|
||||
app,
|
||||
localApp,
|
||||
devMode,
|
||||
plugins
|
||||
}
|
||||
|
||||
routes.init(opts)
|
||||
routes.init(opts)
|
||||
|
||||
server.listen(port, () => {
|
||||
console.log('lamassu-server listening on port ' +
|
||||
port + ' ' + (devMode ? '(http)' : '(https)'))
|
||||
server.listen(port, () => {
|
||||
console.log('lamassu-server listening on port ' +
|
||||
port + ' ' + (devMode ? '(http)' : '(https)'))
|
||||
})
|
||||
|
||||
localServer.listen(localPort, 'localhost', () => {
|
||||
console.log('lamassu-server listening on local port ' + localPort)
|
||||
})
|
||||
})
|
||||
|
||||
localServer.listen(localPort, 'localhost', () => {
|
||||
console.log('lamassu-server listening on local port ' + localPort)
|
||||
})
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err)
|
||||
process.exit(1)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue