Skip to content

Commit

Permalink
Merge pull request #154 from hodlforjesus/fb-carver2d
Browse files Browse the repository at this point in the history
Webpack 3->4 migration, split secrets config, beginning reddit integration
  • Loading branch information
hodlforjesus authored Oct 8, 2019
2 parents 1a0b903 + 09c1d16 commit 259c065
Show file tree
Hide file tree
Showing 10 changed files with 1,172 additions and 525 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ typings/
# dotenv environment variables file
.env

# setings file for syste
# setings file for system
config.js
config.server.js
*.cron_lock

.DS_Store
Expand Down
21 changes: 21 additions & 0 deletions config.server.template.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Keep all your API & secrets here. DO NOT IMPORT THIS FILE IN /client folder
*/
const secretsConfig = {
db: {
host: '127.0.0.1',
port: '27017',
name: 'blockex',
user: 'blockexuser',
pass: 'Explorer!1'
},
rpc: {
host: '127.0.0.1',
port: '52541',
user: 'bulwarkrpc',
pass: 'someverysafepassword',
timeout: 8000, // 8 seconds
},
}

module.exports = { secretsConfig }; // This is returned as an object on purpose so you have to be explicit at stating that you are accessing a secrets config
14 changes: 0 additions & 14 deletions config.template.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,6 @@ const config = {
prefix: '/api',
timeout: '5s'
},
db: {
host: '127.0.0.1',
port: '27017',
name: 'blockex',
user: 'blockexuser',
pass: 'Explorer!1'
},
rpc: {
host: '127.0.0.1',
port: '52541',
user: 'bulwarkrpc',
pass: 'someverysafepassword',
timeout: 8000, // 8 seconds
},
coinDetails: {
name: 'Bulwark',
shortName: 'BWK',
Expand Down
46 changes: 46 additions & 0 deletions cron/social/reddit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

require('babel-polyfill');
const config = require('../../config');
const { exit, rpc } = require('../../lib/cron');
const fetch = require('../../lib/fetch');
const locker = require('../../lib/locker');
const moment = require('moment');
// Models.
const Coin = require('../../model/coin');
const { CarverAddress, CarverMovement } = require('../../model/carver2d');
const { CarverAddressType } = require('../../lib/carver2d');
const { TimeInterval } = require('../../model/timeInterval');
const { BlockRewardDetails } = require('../../model/blockRewardDetails');
const { TimeIntervalType, TimeIntervalColumn } = require('../../lib/timeInterval');

/**
* Gets most reddit posts and stores them in db for later use
*/
const syncRedditPosts = async () => {
}

/**
* Handle locking.
*/
async function update() {
const type = 'social_reddit';
let code = 0;

try {
locker.lock(type);
await syncRedditPosts();
} catch (err) {
console.log(err);
code = 1;
} finally {
try {
locker.unlock(type);
} catch (err) {
console.log(err);
code = 1;
}
exit(code);
}
}

update();
12 changes: 6 additions & 6 deletions lib/db.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@

const config = require('../config');
const { secretsConfig } = require('../config.server');
const promise = require('bluebird');

/**
* Return the DSN string for the mongodb connection.
*/
const getDSN = () => {
return `mongodb://${ config.db.host }:${ config.db.port }/${ config.db.name }`;
return `mongodb://${secretsConfig.db.host}:${secretsConfig.db.port}/${secretsConfig.db.name}`;
};

/**
* Return the options for the mongodb connection.
*/
const getOptions = () => {
return {
auth: { authdb: config.db.name },
auth: { authdb: secretsConfig.db.name },
native_parser: true,
pass: config.db.pass,
pass: secretsConfig.db.pass,
promiseLibrary: promise,
user: config.db.user
user: secretsConfig.db.user
};
};

module.exports = {
module.exports = {
getDSN,
getOptions
};
12 changes: 6 additions & 6 deletions lib/rpc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

const config = require('../config');
const { secretsConfig } = require('../config.server');
const promise = require('bluebird');
const rpc = require('node-bitcoin-rpc');

Expand All @@ -17,13 +17,13 @@ class RPC {
instance = this;

rpc.init(
config.rpc.host,
config.rpc.port,
config.rpc.user,
config.rpc.pass
secretsConfig.rpc.host,
secretsConfig.rpc.port,
secretsConfig.rpc.user,
secretsConfig.rpc.pass
);

rpc.setTimeout(config.rpc.timeout);
rpc.setTimeout(secretsConfig.rpc.timeout);
}

return instance;
Expand Down
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@
"react-router-dom": "^4.2.2",
"react-router-redux": "^4.0.8",
"reactstrap": "next",
"redux": "^3.7.2"
"redux": "^3.7.2",
"snoowrap": "^1.20.0",
"webpack-cli": "^3.3.9"
},
"devDependencies": {
"animate-sass": "^0.8.2",
Expand All @@ -66,14 +68,14 @@
"chai-http": "^3.0.0",
"compression-webpack-plugin": "^1.1.11",
"css-loader": "^0.28.9",
"html-webpack-plugin": "^2.30.1",
"html-webpack-plugin": "^3.2.0",
"mocha": "^5.0.0",
"node-sass": "^4.7.2",
"sass-loader": "^6.0.6",
"style-loader": "^0.20.1",
"uglifyjs-webpack-plugin": "^1.2.4",
"webpack": "^3.11.0",
"webpack-dev-server": ">=3.1.11",
"webpack": "^4.41.0",
"webpack-dev-server": "^3.8.2",
"worker-loader": "^1.1.1"
}
}
37 changes: 23 additions & 14 deletions script/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -130,32 +130,41 @@ installBlockEx () {
git clone https://github.com/bulwark-crypto/bulwark-explorer.git /home/explorer/blockex
cd /home/explorer/blockex
yarn install
cat > /home/explorer/blockex/config.js << EOL
cat > /home/explorer/blockex/config.server.js << EOL
/**
* Global configuration object.
* Keep all your API & secrets here. DO NOT IMPORT THIS FILE IN /client folder
*/
const config = {
api: {
host: 'https://explorer.bulwarkcrypto.com',
port: '3000',
portWorker: '443',
prefix: '/api',
timeout: '5s'
},
const secretsConfig = {
db: {
host: '127.0.0.1',
port: '27017',
name: 'blockex',
user: '$rpcuser',
pass: '$rpcpassword'
user: 'blockexuser',
pass: 'Explorer!1'
},
rpc: {
host: '127.0.0.1',
port: '52541',
user: '$rpcuser',
pass: '$rpcpassword'
user: 'bulwarkrpc',
pass: 'someverysafepassword',
timeout: 8000, // 8 seconds
},
}
module.exports = { secretsConfig }; // This is returned as an object on purpose so you have to be explicit at stating that you are accessing a secrets config
EOL
cat > /home/explorer/blockex/config.js << EOL
/**
* Global configuration object.
*/
const config = {
api: {
host: 'https://explorer.bulwarkcrypto.com',
port: '3000',
portWorker: '443',
prefix: '/api',
timeout: '5s'
},
coinDetails: {
name: 'Bulwark',
shortName: 'BWK',
Expand Down
15 changes: 7 additions & 8 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
const compressionPlugin = require('compression-webpack-plugin');
const htmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');
const uglifyJsPlugin = require('uglifyjs-webpack-plugin');
const webpack = require('webpack');
const config = require('./config')

Expand All @@ -22,7 +21,7 @@ const basePlugins = [
}),
new webpack.DefinePlugin({
'process.env': {
'config.api':JSON.stringify(config.api),
'config.api': JSON.stringify(config.api),
}
}),
new webpack.HotModuleReplacementPlugin(),
Expand All @@ -37,12 +36,12 @@ const prodPlugins = [
algorithm: 'gzip',
asset: '[path].gz[query]'
}),
new webpack.optimize.UglifyJsPlugin({
compress: { warnings: false },
comments: false,
sourceMap: true,
minimize: false
})
/* new webpack.optimize.UglifyJsPlugin({
compress: { warnings: false },
comments: false,
sourceMap: true,
minimize: false
})*/
];

const envPlugins = process.env.NODE_ENV === 'production'
Expand Down
Loading

0 comments on commit 259c065

Please sign in to comment.