Log all requests, using the bunyan format (JSON with certain fields). This
is most easily consumed with the bunyan formatter; see README.md for more details.
This commit is contained in:
parent
8672439358
commit
3c38a932ed
@ -23,6 +23,12 @@ The SSH key used must be the correct format, e.g. generated with:
|
|||||||
|
|
||||||
node bin/server.js config/prod.json
|
node bin/server.js config/prod.json
|
||||||
|
|
||||||
|
The server generates a lot of JSON data about every request. This is easier
|
||||||
|
for a human to handle if they have bunyan installed ("npm install -g bunyan"),
|
||||||
|
and instead:
|
||||||
|
|
||||||
|
node bin/server.js config/prod.json | bunyan
|
||||||
|
|
||||||
# Endpoints
|
# Endpoints
|
||||||
|
|
||||||
## GET /*
|
## GET /*
|
||||||
|
@ -6,6 +6,7 @@ const mod_cueball = require('cueball');
|
|||||||
const mod_crypto = require('crypto');
|
const mod_crypto = require('crypto');
|
||||||
const mod_fs = require('fs');
|
const mod_fs = require('fs');
|
||||||
const mod_sdcauth = require('smartdc-auth');
|
const mod_sdcauth = require('smartdc-auth');
|
||||||
|
const mod_bunyan = require('bunyan');
|
||||||
|
|
||||||
|
|
||||||
// Globals that are assigned to by main(). They are used by proxy() and login().
|
// Globals that are assigned to by main(). They are used by proxy() and login().
|
||||||
@ -25,8 +26,6 @@ const STATIC_RE = new RegExp('^/');
|
|||||||
// from cloudapi to our client caller. Effectively this function is a proxy
|
// from cloudapi to our client caller. Effectively this function is a proxy
|
||||||
// that solely signs the request as it passes through.
|
// that solely signs the request as it passes through.
|
||||||
function proxy(req, res, cb) {
|
function proxy(req, res, cb) {
|
||||||
console.log('### proxy', req.url)
|
|
||||||
|
|
||||||
// return data from cloudapi to the client caller
|
// return data from cloudapi to the client caller
|
||||||
function proxyReturn(err, _, res2, data) {
|
function proxyReturn(err, _, res2, data) {
|
||||||
if (err && !res2) {
|
if (err && !res2) {
|
||||||
@ -71,8 +70,6 @@ function proxy(req, res, cb) {
|
|||||||
headers: headers
|
headers: headers
|
||||||
};
|
};
|
||||||
|
|
||||||
console.dir(opts);
|
|
||||||
|
|
||||||
// make the call to cloudapi
|
// make the call to cloudapi
|
||||||
switch (req.method) {
|
switch (req.method) {
|
||||||
case 'GET': CLOUDAPI.get(opts, proxyReturn); break;
|
case 'GET': CLOUDAPI.get(opts, proxyReturn); break;
|
||||||
@ -89,8 +86,6 @@ console.dir(opts);
|
|||||||
// secure token. Once the user successfully logs in, the token is returned
|
// secure token. Once the user successfully logs in, the token is returned
|
||||||
// through an SSO redirect to token() below.
|
// through an SSO redirect to token() below.
|
||||||
function login(req, res, cb) {
|
function login(req, res, cb) {
|
||||||
console.log('### login');
|
|
||||||
|
|
||||||
const query = {
|
const query = {
|
||||||
permissions: '{"cloudapi":["/my/*"]}',
|
permissions: '{"cloudapi":["/my/*"]}',
|
||||||
returnto: CONFIG.urls.local,
|
returnto: CONFIG.urls.local,
|
||||||
@ -159,9 +154,15 @@ function main() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const server = mod_restify.createServer(options);
|
const server = mod_restify.createServer(options);
|
||||||
|
server.use(mod_restify.requestLogger());
|
||||||
server.use(mod_restify.authorizationParser());
|
server.use(mod_restify.authorizationParser());
|
||||||
server.use(mod_restify.bodyReader());
|
server.use(mod_restify.bodyReader());
|
||||||
|
|
||||||
|
// log requests
|
||||||
|
server.on('after', mod_restify.auditLogger({
|
||||||
|
log: mod_bunyan.createLogger({ name: 'proxy' })
|
||||||
|
}));
|
||||||
|
|
||||||
// login path is /api/login
|
// login path is /api/login
|
||||||
server.get(LOGIN_PATH, login);
|
server.get(LOGIN_PATH, login);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user