diff --git a/config/custom-environment-variables.json b/config/custom-environment-variables.json index be110732..aa3fad52 100644 --- a/config/custom-environment-variables.json +++ b/config/custom-environment-variables.json @@ -1,6 +1,8 @@ { "WalletConfig": { - "LbryAddress": "LBRY_WALLET_ADDRESS" + "LbryPayAddress": "LBRY_PAY_ADDRESS", + "LbryClaimAddress": "LBRY_CLAIM_ADDRESS", + "LbryChangeAddress": "LBRY_CHANGE_ADDRESS" }, "Database": { "MySqlConnectionUri": "MYSQL_CONNECTION_STRING" diff --git a/config/default.json b/config/default.json index 546378c7..a50953a0 100644 --- a/config/default.json +++ b/config/default.json @@ -1,6 +1,8 @@ { "WalletConfig": { - "LbryAddress": "none" + "LbryPayAddress": "none", + "LbryClaimAddress": "none", + "LbryChangeAddress": "none" }, "AnalyticsConfig":{ "GoogleId": "none" diff --git a/config/development.json b/config/development.json index 38c7affe..691528f2 100644 --- a/config/development.json +++ b/config/development.json @@ -1,6 +1,8 @@ { "WalletConfig": { - "LbryAddress": "none" + "LbryPayAddress": "none", + "LbryClaimAddress": "none", + "LbryChangeAddress": "none" }, "AnalyticsConfig":{ "GoogleId": "UA-100747990-1" diff --git a/config/production.json b/config/production.json index 56fde915..05161783 100644 --- a/config/production.json +++ b/config/production.json @@ -1,6 +1,8 @@ { "WalletConfig": { - "LbryAddress": "none" + "LbryPayAddress": "none", + "LbryClaimAddress": "none", + "LbryChangeAddress": "none" }, "AnalyticsConfig":{ "GoogleId": "UA-60403362-2" diff --git a/config/test.json b/config/test.json index b74d2997..bab71bfa 100644 --- a/config/test.json +++ b/config/test.json @@ -1,6 +1,8 @@ { "WalletConfig": { - "LbryAddress": "none" + "LbryPayAddress": "none", + "LbryClaimAddress": "none", + "LbryChangeAddress": "none" }, "AnalyticsConfig":{ "GoogleId": "UA-100747990-1" diff --git a/helpers/libraries/analytics.js b/helpers/libraries/analytics.js index a91ac73b..84ee2618 100644 --- a/helpers/libraries/analytics.js +++ b/helpers/libraries/analytics.js @@ -4,9 +4,15 @@ const logger = require('winston'); module.exports = { postToAnalytics: (action, url, ipAddress, result) => { logger.silly('creating record for analytics'); + // make sure the result is a string if (result && (typeof result !== 'string')) { result = result.toString(); } + // // make sure the ip address(es) are a string + if (ipAddress && (typeof ipAddress !== 'string')) { + ipAddress = ipAddress.toString(); + } + // create record in the db db.Analytics.create({ action, url, diff --git a/helpers/libraries/publishHelpers.js b/helpers/libraries/publishHelpers.js index 57a87208..045f5ee6 100644 --- a/helpers/libraries/publishHelpers.js +++ b/helpers/libraries/publishHelpers.js @@ -1,12 +1,14 @@ const logger = require('winston'); const config = require('config'); -const walletAddress = config.get('WalletConfig.LbryAddress'); const fs = require('fs'); module.exports = { createPublishParams: (name, filePath, license, nsfw) => { logger.debug(`Creating Publish Parameters for "${name}"`); - // ensure nsfw is a boolean + // const payAddress = config.get('WalletConfig.LbryPayAddress'); + const claimAddress = config.get('WalletConfig.LbryClaimAddress'); + // const changeAddress = config.get('WalletConfig.LbryChangeAddress'); + // filter nsfw and ensure it is a boolean if (nsfw === false) { nsfw = false; } else if (nsfw.toLowerCase === 'false') { @@ -32,8 +34,8 @@ module.exports = { license, nsfw, }, - claim_address : walletAddress, - change_address: walletAddress, + claim_address: claimAddress, + // change_address: changeAddress, }; logger.debug('publishParams:', publishParams); return publishParams; diff --git a/routes/home-routes.js b/routes/home-routes.js index 1d747edf..d36d8f6c 100644 --- a/routes/home-routes.js +++ b/routes/home-routes.js @@ -3,8 +3,9 @@ const { postToAnalytics } = require('../helpers/libraries/analytics'); module.exports = app => { // route for the home page - app.get('/', ({ originalUrl, ip }, res) => { - logger.debug(`GET request on ${originalUrl} from ${ip}`); + app.get('/', ({ originalUrl, ip, headers }, res) => { + logger.verbose(`GET request on ${originalUrl} from ${ip}`); + logger.debug(`headers ${JSON.stringify(headers)}`); res.status(200).render('index'); }); // a catch-all route if someone visits a page that does not exist diff --git a/routes/serve-routes.js b/routes/serve-routes.js index 827054f6..16025638 100644 --- a/routes/serve-routes.js +++ b/routes/serve-routes.js @@ -34,31 +34,35 @@ function serveFile ({ fileName, fileType, filePath }, res) { module.exports = (app) => { // route to fetch one free public claim - app.get('/:name/:claim_id', ({ originalUrl, params, ip }, res) => { - logger.debug(`GET request on ${originalUrl} from ${ip}`); + app.get('/:name/:claim_id', ({ originalUrl, params, ip, ips, headers }, res) => { + logger.verbose(`GET request on ${originalUrl} from ${ip}`); + logger.debug(`ips >> ${JSON.stringify(ips)}`); + logger.debug(`headers >> ${JSON.stringify(headers)}`); // begin image-serve processes serveController .getClaimByClaimId(params.name, params.claim_id) .then(fileInfo => { - postToAnalytics('serve', originalUrl, ip, 'success'); + postToAnalytics('serve', originalUrl, ips, 'success'); serveFile(fileInfo, res); }) .catch(error => { - errorHandlers.handleRequestError('serve', originalUrl, ip, error, res); + errorHandlers.handleRequestError('serve', originalUrl, ips, error, res); }); }); // route to fetch one free public claim - app.get('/:name', ({ originalUrl, params, ip }, res) => { - logger.debug(`GET request on ${originalUrl} from ${ip}`); + app.get('/:name', ({ originalUrl, params, ip, ips, headers }, res) => { + logger.verbose(`GET request on ${originalUrl} from ${ip}`); + logger.debug(`ips >> ${JSON.stringify(ips)}`); + logger.debug(`headers >> ${JSON.stringify(headers)}`); // begin image-serve processes serveController .getClaimByName(params.name) .then(fileInfo => { - postToAnalytics('serve', originalUrl, ip, 'success'); + postToAnalytics('serve', originalUrl, ips, 'success'); serveFile(fileInfo, res); }) .catch(error => { - errorHandlers.handleRequestError('serve', originalUrl, ip, error, res); + errorHandlers.handleRequestError('serve', originalUrl, ips, error, res); }); }); }; diff --git a/server.js b/server.js index 22c6fca2..6d7e9102 100644 --- a/server.js +++ b/server.js @@ -16,15 +16,16 @@ require('./config/loggerSetup.js')(winston, logLevel, logDir); // set port const PORT = 3000; -// initialize express app +// create an Express application const app = express(); // require our models for syncing const db = require('./models'); -// make express look in the public directory for assets (css/js/img) +// serve static files from public directory (css/js/img) app.use(express.static(`${__dirname}/public`)); // configure express app +app.enable('trust proxy'); // trust the proxy to get ip address for us app.use(bodyParser.json()); // for parsing application/json app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded app.use(siofu.router); @@ -68,6 +69,7 @@ const http = require('./routes/sockets-routes.js')(app, siofu, hostedContentPath // start server db.sequelize.sync().then(() => { http.listen(PORT, () => { + winston.info('Trusting proxy?', app.get('trust proxy')); winston.info(`Server is listening on PORT ${PORT}`); }); });