This repository has been archived by the owner on Apr 17, 2023. It is now read-only.
/
appApi.js
110 lines (88 loc) · 3.25 KB
/
appApi.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
Partout [Everywhere] - Policy-Based Configuration Management for the
Data-Driven-Infrastructure.
Copyright (C) 2015-2016 Graham Lee Bevan <graham.bevan@ntlworld.com>
This file is part of Partout.
Partout is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*jslint node: true */
/*jshint esversion: 6 */
'use strict';
const console = require('better-console'),
Q = require('q'),
cfg = new (require('./etc/partout.conf.js'))(),
fs = require('fs'),
u = require('util'),
ca = new (require('./lib/ca'))(),
express = require('express'),
feathers = require('feathers'),
routerApi = express.Router(),
httpsApi = require('https'),
compression = require('compression'),
bodyParser = require('body-parser'),
morgan = require('morgan'),
logger = morgan('API :: :method :url :status :response-time ms - :res[content-length] bytes'),
passport = require('passport'),
serverMetrics = new (require('./lib/server_metrics'))();
const debug = require('debug').debug('partout:appApi');
Q.longStackSupport = true;
passport.serializeUser(function(user, done) {
done(null, user);
});
passport.deserializeUser(function(obj, done) {
done(null, obj);
});
/**
* Express app for the Master API
* @class appApi
* @memberof App
*/
var AppApi = function (opts, appUi) {
var self = this;
// self.app = express();
self.app = feathers();
var optionsApi = {
key: fs.readFileSync(ca.masterApiPrivateKeyFile),
cert: fs.readFileSync(ca.masterApiCertFile),
ca: [
fs.readFileSync(ca.agentSignerCertFile, 'utf8'),
fs.readFileSync(ca.intCertFile, 'utf8'),
fs.readFileSync(ca.rootCertFile, 'utf8')
// cert to verify agents
/*
* root cert placed in /usr/share/ca-certificates/partout and updated
* /etc/ca-certificates.conf to point to it.
* run update-ca-certificates
* only include intermediate ca here, and import this into
* browsers cert stores
*/
//fs.readFileSync(ca.rootCertFile)
],
requestCert: true,
rejectUnauthorized: false
};
self.app.opts = opts;
self.report_issue = self.app.report_issue = appUi.report_issue;
self.app
.use(compression())
.use(logger)
.use(bodyParser.json({limit: '50mb'}))
.use(bodyParser.urlencoded({ extended: true }));
require('./lib/api/routes')(routerApi, cfg, self.app, appUi, serverMetrics);
self.app
.use('/', routerApi)
.use(express.static('public'));
httpsApi.createServer(optionsApi, self.app)
.listen(cfg.partout_api_port);
console.info('Master API listening on port', cfg.partout_api_port);
};
module.exports = AppApi;