fxa-auth-server/bin/key_server.js

119 строки
2.8 KiB
JavaScript
Исходник Обычный вид История

2013-07-26 05:46:16 +04:00
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
var config = require('../config').root()
var jwtool = require('fxa-jwtool')
function main() {
2013-12-12 22:02:33 +04:00
var log = require('../log')(config.log.level)
2013-11-26 05:27:08 +04:00
function logStatInfo() {
log.stat(server.stat())
log.stat(Password.stat())
}
2014-03-15 08:50:49 +04:00
log.event('config', config)
if (config.env !== 'prod') {
2013-11-26 05:27:08 +04:00
log.info(config, "starting config")
}
2014-02-01 03:42:49 +04:00
var error = require('../error')
2014-01-16 01:23:29 +04:00
var Token = require('../tokens')(log, config.tokenLifetimes)
var Password = require('../crypto/password')(log, config)
2013-10-27 06:49:33 +04:00
2015-03-26 08:52:04 +03:00
var signer = require('../signer')(config.secretKeyFile, config.domain)
var serverPublicKey = jwtool.JWK.fromFile(
config.publicKeyFile,
{
2015-03-26 08:52:04 +03:00
algorithm: 'RS',
use: 'sig',
kid: 'dev-1',
kty: 'RSA'
}
)
2013-10-30 00:46:09 +04:00
var Customs = require('../customs')(log, error)
2013-10-30 00:46:09 +04:00
var Server = require('../server')
var server = null
2014-02-27 03:57:31 +04:00
var mailer = null
var statsInterval = null
var database = null
var customs = null
2014-06-02 02:04:39 +04:00
require('../mailer')(config, log)
2014-03-10 04:33:52 +04:00
.done(
2014-02-27 03:57:31 +04:00
function(m) {
mailer = m
2013-10-30 00:46:09 +04:00
var DB = require('../db')(
config.db.backend,
log,
error,
Token.SessionToken,
Token.KeyFetchToken,
Token.AccountResetToken,
Token.PasswordForgotToken,
Token.PasswordChangeToken
)
2013-10-30 00:46:09 +04:00
DB.connect(config[config.db.backend])
.done(
function (db) {
database = db
customs = new Customs(config.customsUrl)
var routes = require('../routes')(
log,
error,
serverPublicKey,
signer,
db,
mailer,
Password,
config,
customs
)
2014-03-10 04:33:52 +04:00
server = Server.create(log, error, config, routes, db)
2013-12-06 02:52:55 +04:00
server.start(
function () {
log.info({ op: 'server.start.1', msg: 'running on ' + server.info.uri })
}
)
statsInterval = setInterval(logStatInfo, 15000)
},
function (err) {
log.error({ op: 'DB.connect', err: { message: err.message } })
process.exit(1)
}
)
2013-10-30 00:46:09 +04:00
}
)
process.on(
'uncaughtException',
function (err) {
log.fatal(err)
process.exit(8)
}
)
process.on('SIGINT', shutdown)
log.on('error', shutdown)
function shutdown() {
log.info({ op: 'shutdown' })
clearInterval(statsInterval)
server.stop(
function () {
customs.close()
mailer.stop()
database.close()
}
)
}
}
main()