changed config

This commit is contained in:
Danny Coates 2017-06-06 23:52:56 -07:00
parent af4edfef16
commit 8bb42c137a
No known key found for this signature in database
GPG Key ID: 4C442633C62E00CB
3 changed files with 514 additions and 305 deletions

767
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,13 +1,24 @@
const convict = require('convict'); const convict = require('convict');
let api_key = 'INSERT API KEY HERE';
let conf = convict({ let conf = convict({
aws_credentials: { bitly_key: {
region: 'us-west-2', format: String,
bucketName: 'testpilot-p2p' env: 'P2P_BITLY_KEY'
}, },
bitly_credentials: { s3_bucket: {
api_key: api_key format: String,
env: 'P2P_S3_BUCKET'
},
redis_host: {
format: String,
default: 'localhost',
env: 'P2P_REDIS_HOST'
},
listen_port: {
format: 'port',
default: 1443,
arg: 'port',
env: 'P2P_LISTEN_PORT'
}, },
env: { env: {
format: ['production', 'development'], format: ['production', 'development'],

View File

@ -8,8 +8,6 @@ const conf = require('./config.js');
const stream = require('stream'); const stream = require('stream');
const fetch = require('node-fetch'); const fetch = require('node-fetch');
let aws_credentials = conf.aws_credentials;
let bitly_credentials = conf.bitly_credentials;
let isProduction = conf.env === 'production'; let isProduction = conf.env === 'production';
const AWS = require('aws-sdk'); const AWS = require('aws-sdk');
@ -44,7 +42,7 @@ app.get('/assets/download/:id', (req, res) => {
res.sendStatus(404); res.sendStatus(404);
} else { } else {
let params = { let params = {
Bucket: aws_credentials.bucketName, Bucket: config.s3_bucket,
Key: id Key: id
}; };
@ -91,7 +89,7 @@ app.post('/delete/:id', (req, res) => {
} else { } else {
redis_client.del(id); redis_client.del(id);
let params = { let params = {
Bucket: aws_credentials.bucketName, Bucket: config.s3_bucket,
Key: id Key: id
}; };
@ -117,7 +115,7 @@ app.post('/upload/:id', (req, res, next) => {
console.log('Uploading: ' + filename); console.log('Uploading: ' + filename);
let params = { let params = {
Bucket: aws_credentials.bucketName, Bucket: config.s3_bucket,
Key: req.params.id, Key: req.params.id,
Body: file Body: file
}; };
@ -133,18 +131,11 @@ app.post('/upload/:id', (req, res, next) => {
redis_client.expire(id, 86400000); redis_client.expire(id, 86400000);
console.log('Upload Finished of ' + filename); console.log('Upload Finished of ' + filename);
let url = `${req.protocol}://${req.get('host')}/download/${req.params.id}/`;
if (isProduction) { if (config.bitly_key) {
let url =
req.protocol +
`://` +
req.get('host') +
'/download/' +
req.params.id +
'/';
fetch( fetch(
'https://api-ssl.bitly.com/v3/shorten?access_token=' + 'https://api-ssl.bitly.com/v3/shorten?access_token=' +
bitly_credentials.api_key + config.bitly_key +
'&longUrl=' + '&longUrl=' +
encodeURIComponent(url) + encodeURIComponent(url) +
'&format=txt' '&format=txt'
@ -169,14 +160,10 @@ app.post('/upload/:id', (req, res, next) => {
}); });
}); });
let server = app.listen(3000, () => { let server = app.listen(conf.listen_port, () => {
console.log('Portal app listening on port 3000!'); console.log(`Portal app listening on port ${conf.listen_port}!`);
}); });
let validateID = route_id => { let validateID = route_id => {
return route_id.match(/^[0-9a-fA-F]{32}$/) !== null; return route_id.match(/^[0-9a-fA-F]{32}$/) !== null;
}; };
if (bitly_credentials.api_key === 'INSERT API KEY HERE') {
throw new Error('Copy paste a bitly API key into server/config.js');
}