Skip to content

Commit 5d204b4

Browse files
committed
V2 release!
1 parent aae726f commit 5d204b4

File tree

27 files changed

+192
-288
lines changed

27 files changed

+192
-288
lines changed

bin/deploy.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ const s3 = new AWS.S3({
1414
region: 'eu-west-1',
1515
});
1616

17+
const cf = new AWS.CloudFront({});
18+
1719
function promisify(fn, thisScope) {
1820
return function decorator(...args) {
1921
return new Promise((resolve, reject) => {
@@ -124,5 +126,23 @@ const themes = path.join(__dirname, '../node_modules/codemirror/theme');
124126

125127
deploy(dist)
126128
.on('end', () => {
127-
deploy(themes, path.join(__dirname, '../node_modules'));
129+
deploy(themes, path.join(__dirname, '../node_modules'))
130+
.on('end', () => {
131+
const params = {
132+
DistributionId: 'EDV35IT95U5Q7',
133+
InvalidationBatch: {
134+
CallerReference: `${Date.now()}`,
135+
Paths: {
136+
Quantity: 1,
137+
Items: ['/index.html'],
138+
}
139+
}
140+
};
141+
142+
cf.createInvalidation(params, (err, data) => {
143+
if (err) return debug('Failed invalidation:', err.message);
144+
145+
debug('Succesfully invalidated index.html');
146+
});
147+
});
128148
});

config/environments.config.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ module.exports = {
1414

1515
staging: (config) => ({
1616
bucket_name : 'staging.es6console.com',
17-
api_server_host : 'https://api-staging.es6console.com/v1/',
18-
s3_server_host : 'http://staging.es6console.com/',
17+
api_server_host : 'https://zl9ct7ehp9.execute-api.eu-west-1.amazonaws.com/dev/',
18+
s3_server_host : 'http://staging.es6console.com.s3-website-eu-west-1.amazonaws.com/',
19+
snippet_bucket_url: 'https://s3-eu-west-1.amazonaws.com/es6console-prod-snippets/',
20+
1921
compiler_public_path : '/',
2022
compiler_fail_on_warning : false,
2123
compiler_hash_type : 'chunkhash',
@@ -34,6 +36,8 @@ module.exports = {
3436
bucket_name : 'es6console.com',
3537
api_server_host : 'https://api.es6console.com/v1/',
3638
s3_server_host : 'http://es6console.com/',
39+
snippet_bucket_url: 'https://s3-eu-west-1.amazonaws.com/es6console-prod-snippets/',
40+
3741
compiler_public_path : '/',
3842
compiler_fail_on_warning : false,
3943
compiler_hash_type : 'chunkhash',

config/project.config.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@ const config = {
3030
// ----------------------------------
3131
// API Server Configuration
3232
// ----------------------------------
33-
api_server_host : 'http://localhost:3000/', // use string 'localhost' to prevent exposure on local network
34-
s3_server_host : 'http://localhost:8000/',
33+
api_server_host : `http://localhost:3000/`, // use string 'localhost' to prevent exposure on local network
34+
s3_server_host : 'http://staging.es6console.com/',
3535

3636
// ----------------------------------
3737
// AWS Configuration
3838
// ----------------------------------
3939
bucket_name : 'staging.es6console.com',
40+
snippet_bucket_url: 'https://s3-eu-west-1.amazonaws.com/es6console-prod-snippets/',
4041

4142
// ----------------------------------
4243
// Compiler Configuration
@@ -147,6 +148,7 @@ config.globals = {
147148
'__BASENAME__' : JSON.stringify(process.env.BASENAME || ''),
148149
'API_SERVER_HOST' : JSON.stringify(config.api_server_host),
149150
'S3_SERVER_HOST': JSON.stringify(config.s3_server_host),
151+
'SNIPPET_BUCKET_URL': JSON.stringify(config.snippet_bucket_url),
150152
}
151153

152154
module.exports = config
Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
'use strict';
2-
const dynamo = require('./dynamodb');
2+
const AWS = require('aws-sdk');
3+
const project = require('../config/project.config');
34

45
const options = {
56
region: 'eu-west-1',
67
};
78

9+
// if (process.env.IS_OFFLINE) {
10+
// options.s3ForcePathStyle = true;
11+
// options.endpoint = new AWS.Endpoint(project.s3_server_host);
12+
// }
13+
14+
const S3 = new AWS.S3(options);
15+
816
module.exports.handler = (event, context, callback) => {
917
let body;
1018

@@ -19,18 +27,13 @@ module.exports.handler = (event, context, callback) => {
1927
const snippetId = parseInt(now, 10).toString(36);
2028

2129
const params = {
22-
TableName: process.env.DYNAMODB_TABLE,
23-
Item: {
24-
id: {
25-
S: snippetId,
26-
},
27-
code: {
28-
S: body.code,
29-
}
30-
}
30+
Bucket: process.env.SNIPPET_BUCKET_NAME,
31+
Key: snippetId,
32+
Body: new Buffer(body.code),
33+
ACL: 'public-read',
3134
};
3235

33-
dynamo.putItem(params, (err, data) => {
36+
S3.upload(params, (err, data) => {
3437
if (err) {
3538
console.error(err);
3639
return callback(err);
File renamed without changes.

0 commit comments

Comments
 (0)