Skip to content

Commit 072ece4

Browse files
committed
Fixes #497 by adding support for an optional new env variable, S3_BUCKET_URL_BASE
1 parent c820b62 commit 072ece4

File tree

7 files changed

+21
-9
lines changed

7 files changed

+21
-9
lines changed

client/modules/IDE/actions/uploader.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import axios from 'axios';
22
import { createFile } from './files';
33

44
const textFileRegex = /(text\/|application\/json)/;
5-
const s3BucketHttps = `https://s3-${process.env.AWS_REGION}.amazonaws.com/${process.env.S3_BUCKET}/`;
5+
const s3BucketHttps = process.env.S3_BUCKET_URL_BASE ||
6+
`https://s3-${process.env.AWS_REGION}.amazonaws.com/${process.env.S3_BUCKET}/`;
67
const ROOT_URL = process.env.API_URL;
78
const MAX_LOCAL_FILE_SIZE = 80000; // bytes, aka 80 KB
89

client/modules/IDE/components/FileUploader.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import { bindActionCreators } from 'redux';
44
import { connect } from 'react-redux';
55
import * as UploaderActions from '../actions/uploader';
66

7-
const s3Bucket = `https://s3-${process.env.AWS_REGION}.amazonaws.com/${process.env.S3_BUCKET}/`;
7+
const s3Bucket = process.env.S3_BUCKET_URL_BASE ||
8+
`https://s3-${process.env.AWS_REGION}.amazonaws.com/${process.env.S3_BUCKET}/`;
89

910
class FileUploader extends React.Component {
1011
componentDidMount() {

index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,11 @@ if (process.env.NODE_ENV === 'production') {
44
}
55
require('babel-register');
66
require('babel-polyfill');
7-
require('dotenv').config();
8-
require('./server/server');
7+
let parsed = require('dotenv').config();
8+
//// in development, let .env values override those in the environment already (i.e. in docker-compose.yml)
9+
if (process.env.NODE_ENV === 'development') {
10+
for (let key in parsed) {
11+
process.env[key] = parsed[key];
12+
}
13+
}
14+
require('./server/server');

server/controllers/aws.controller.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ const client = s3.createClient({
1717
},
1818
});
1919

20-
const s3Bucket = `https://s3-${process.env.AWS_REGION}.amazonaws.com/${process.env.S3_BUCKET}/`;
20+
const s3Bucket = process.env.S3_BUCKET_URL_BASE ||
21+
`https://s3-${process.env.AWS_REGION}.amazonaws.com/${process.env.S3_BUCKET}/`;
2122

2223
function getExtension(filename) {
2324
const i = filename.lastIndexOf('.');

server/migrations/s3UnderUser.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ let client = s3.createClient({
1515
maxAsyncS3: 20,
1616
s3RetryCount: 3,
1717
s3RetryDelay: 1000,
18-
multipartUploadThreshold: 20971520, // this is the default (20 MB)
19-
multipartUploadSize: 15728640, // this is the default (15 MB)
18+
multipartUploadThreshold: 20971520, // this is the default (20 MB)
19+
multipartUploadSize: 15728640, // this is the default (15 MB)
2020
s3Options: {
2121
accessKeyId: `${process.env.AWS_ACCESS_KEY}`,
2222
secretAccessKey: `${process.env.AWS_SECRET_KEY}`,
@@ -43,7 +43,8 @@ Project.find({}, (err, projects) => {
4343
console.log(err);
4444
})
4545
.on('end', () => {
46-
file.url = `https://s3-${process.env.AWS_REGION}.amazonaws.com/${process.env.S3_BUCKET}/${userId}/${key}`;
46+
file.url = (process.env.S3_BUCKET_URL_BASE ||
47+
`https://s3-${process.env.AWS_REGION}.amazonaws.com/${process.env.S3_BUCKET}`) + `/${userId}/${key}`;
4748
project.save((err, savedProject) => {
4849
console.log(`updated file ${key}`);
4950
});
@@ -54,4 +55,4 @@ Project.find({}, (err, projects) => {
5455
}
5556
});
5657
});
57-
});
58+
});

webpack.config.dev.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ module.exports = {
4141
JSON.stringify(false),
4242
'NODE_ENV': JSON.stringify('development'),
4343
'S3_BUCKET': '"' + process.env.S3_BUCKET + '"',
44+
'S3_BUCKET_URL_BASE': '"' + process.env.S3_BUCKET_URL_BASE + '"',
4445
'AWS_REGION': '"' + process.env.AWS_REGION + '"',
4546
}
4647
})

webpack.config.prod.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ module.exports = {
8282
'API_URL': '"' + process.env.API_URL + '"',
8383
'NODE_ENV': JSON.stringify('production'),
8484
'S3_BUCKET': '"' + process.env.S3_BUCKET + '"',
85+
'S3_BUCKET_URL_BASE': '"' + process.env.S3_BUCKET_URL_BASE + '"',
8586
'AWS_REGION': '"' + process.env.AWS_REGION + '"'
8687
}
8788
}),

0 commit comments

Comments
 (0)