Skip to content

Commit

Permalink
Merge pull request #460 from Bitcoin-com/stage
Browse files Browse the repository at this point in the history
v3.11.2
  • Loading branch information
Gabriel Cardona authored Jun 13, 2019
2 parents 0f01c26 + 6d31142 commit 5a56b42
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 12 deletions.
7 changes: 5 additions & 2 deletions dist/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
var express = require("express");
// Middleware
var route_ratelimit_1 = require("./middleware/route-ratelimit");
var req_logging_1 = require("./middleware/req-logging");
var path = require("path");
var logger = require("morgan");
var wlogger = require("./util/winston-logging");
Expand Down Expand Up @@ -67,12 +68,14 @@ app.enable("trust proxy");
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "jade");
app.use("/public", express.static(__dirname + "/public"));
//app.use(logger("dev"))
app.use(logger(":remote-addr :remote-user :method :url :status :response-time ms - :res[content-length]"));
// Log each request to the console with IP addresses.
app.use(logger(":remote-addr :remote-user :method :url :status :response-time ms - :res[content-length] :user-agent"));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, "public")));
// Local logging middleware for tracking incoming connection information.
app.use("/", req_logging_1.logReqInfo);
//
// let username = process.env.USERNAME;
// let password = process.env.PASSWORD;
Expand Down
38 changes: 38 additions & 0 deletions dist/middleware/req-logging.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"use strict";
/*
This middleware logs connection information to local logs. It gives the ability
to detect when the server is being DDOS attacked, and also to collect metrics,
like the most popular endpoints.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var wlogger = require("../util/winston-logging");
// Used for debugging and iterrogating JS objects.
var util = require("util");
util.inspect.defaultOptions = { depth: 1 };
var logReqInfo = function (req, res, next) {
/*
//console.log(`req: ${util.inspect(req)}`)
console.log(`req.headers: ${util.inspect(req.headers)}`)
console.log(`req.url: ${req.url}`)
console.log(`req.method: ${req.method}`)
console.log(`req.sws.ip: ${req.sws.ip}`)
console.log(`req.sws.real_ip: ${req.sws.real_ip}`)
console.log(`req.body: ${util.inspect(req.body)}`)
console.log(` `)
console.log(` `)
*/
var ip = req.sws.real_ip;
var method = req.method;
var url = req.url;
var dataToLog = {
headers: req.headers,
url: url,
method: method,
ip: req.sws.ip,
real_ip: ip,
body: req.body
};
wlogger.verbose("Request: " + ip + " " + method + " " + url, dataToLog);
next();
};
exports.logReqInfo = logReqInfo;
2 changes: 1 addition & 1 deletion dist/public/bitcoin-com-mainnet-rest-v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@
"openapi": "3.0.0",
"info": {
"description": "rest.bitcoin.com is the REST layer for Bitcoin.com's Cloud. More info: [developer.bitcoin.com/rest](https://developer.bitcoin.com/rest). Chatroom [geni.us/CashDev](http://geni.us/CashDev)",
"version": "3.11.1",
"version": "3.11.2",
"title": "REST",
"license": {
"name": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion dist/public/bitcoin-com-testnet-rest-v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@
"openapi": "3.0.0",
"info": {
"description": "trest.bitcoin.com is the REST layer for Bitcoin.com's Cloud. More info: [developer.bitcoin.com/rest](https://developer.bitcoin.com/rest). Chatroom [geni.us/CashDev](http://geni.us/CashDev)",
"version": "3.11.1",
"version": "3.11.2",
"title": "REST",
"license": {
"name": "MIT",
Expand Down
4 changes: 3 additions & 1 deletion dist/util/winston-logging.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ var winston = require("winston");
require("winston-daily-rotate-file");
var NETWORK = process.env.NETWORK;
// Configure daily-rotation transport.
// Configured to only save 20 megs worth of files. Specifically 20 files of
// 1 megabyte each. Old log files will be deleted to make room for new log files.
var transport = new winston.transports.DailyRotateFile({
filename: __dirname + "/../../logs/rest-" + NETWORK + "-%DATE%.log",
datePattern: "YYYY-MM-DD",
zippedArchive: false,
maxSize: "1m",
maxFiles: "5d",
maxFiles: "100",
format: winston.format.combine(winston.format.timestamp(), winston.format.json())
});
transport.on("rotate", function (oldFilename, newFilename) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rest.bitcoin.com",
"version": "3.11.1",
"version": "3.11.2",
"description": "REST API for Bitcoin.com's Cloud",
"author": "Gabriel Cardona <[email protected]>",
"contributors": [
Expand Down
10 changes: 9 additions & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import * as express from "express"
// Middleware
import { routeRateLimit } from "./middleware/route-ratelimit"
import { logReqInfo } from "./middleware/req-logging"

const path = require("path")
const logger = require("morgan")
Expand Down Expand Up @@ -87,13 +88,20 @@ app.set("view engine", "jade")
app.use("/public", express.static(`${__dirname}/public`))

// Log each request to the console with IP addresses.
app.use(logger(`:remote-addr :remote-user :method :url :status :response-time ms - :res[content-length] :user-agent`))
app.use(
logger(
`:remote-addr :remote-user :method :url :status :response-time ms - :res[content-length] :user-agent`
)
)

app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: false }))
app.use(cookieParser())
app.use(express.static(path.join(__dirname, "public")))

// Local logging middleware for tracking incoming connection information.
app.use(`/`, logReqInfo)

//
// let username = process.env.USERNAME;
// let password = process.env.PASSWORD;
Expand Down
59 changes: 59 additions & 0 deletions src/middleware/req-logging.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
This middleware logs connection information to local logs. It gives the ability
to detect when the server is being DDOS attacked, and also to collect metrics,
like the most popular endpoints.
*/

import * as express from "express"
const wlogger = require("../util/winston-logging")

// Used for debugging and iterrogating JS objects.
const util = require("util")
util.inspect.defaultOptions = { depth: 1 }

// Add the 'locals' property to the express.Request interface.
declare global {
namespace Express {
interface Request {
locals: any,
sws: any
}
}
}

const logReqInfo = function(
req: express.Request,
res: express.Response,
next: express.NextFunction
) {

/*
//console.log(`req: ${util.inspect(req)}`)
console.log(`req.headers: ${util.inspect(req.headers)}`)
console.log(`req.url: ${req.url}`)
console.log(`req.method: ${req.method}`)
console.log(`req.sws.ip: ${req.sws.ip}`)
console.log(`req.sws.real_ip: ${req.sws.real_ip}`)
console.log(`req.body: ${util.inspect(req.body)}`)
console.log(` `)
console.log(` `)
*/
const ip = req.sws.real_ip
const method = req.method
const url = req.url

const dataToLog = {
headers: req.headers,
url: url,
method: method,
ip: req.sws.ip,
real_ip: ip,
body: req.body
}

wlogger.verbose(`Request: ${ip} ${method} ${url}`, dataToLog)

next()
}

export { logReqInfo }
6 changes: 4 additions & 2 deletions src/util/winston-logging.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ require("winston-daily-rotate-file")
var NETWORK = process.env.NETWORK

// Configure daily-rotation transport.
// Configured to only save 20 megs worth of files. Specifically 20 files of
// 1 megabyte each. Old log files will be deleted to make room for new log files.
var transport = new winston.transports.DailyRotateFile({
filename: `${__dirname}/../../logs/rest-${NETWORK}-%DATE%.log`,
datePattern: "YYYY-MM-DD",
zippedArchive: false,
maxSize: "1m",
maxFiles: "5d",
maxSize: "1m", // 1 megabyte per file.
maxFiles: "100", // Will overwrite old log files after 100 megs used.
format: winston.format.combine(
winston.format.timestamp(),
winston.format.json()
Expand Down
2 changes: 1 addition & 1 deletion swaggerJSONFiles/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"openapi": "3.0.0",
"info": {
"description": "The Bitcoin Cash JSON PRC over HTTP",
"version": "3.11.1",
"version": "3.11.2",
"title": "REST",
"license": {
"name": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion swaggerJSONFilesBuilt/mainnet/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"openapi": "3.0.0",
"info": {
"description": "rest.bitcoin.com is the REST layer for Bitcoin.com's Cloud. More info: [developer.bitcoin.com/rest](https://developer.bitcoin.com/rest). Chatroom [geni.us/CashDev](http://geni.us/CashDev)",
"version": "3.11.1",
"version": "3.11.2",
"title": "REST",
"license": {
"name": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion swaggerJSONFilesBuilt/testnet/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"openapi": "3.0.0",
"info": {
"description": "trest.bitcoin.com is the REST layer for Bitcoin.com's Cloud. More info: [developer.bitcoin.com/rest](https://developer.bitcoin.com/rest). Chatroom [geni.us/CashDev](http://geni.us/CashDev)",
"version": "3.11.1",
"version": "3.11.2",
"title": "REST",
"license": {
"name": "MIT",
Expand Down

0 comments on commit 5a56b42

Please sign in to comment.