Skip to content

Commit 5d204b4

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

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
File renamed without changes.

lambda/storage/api/create.js renamed to lambda/api/create.js

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.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

lambda/storage/package.json renamed to lambda/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "storage",
2+
"name": "es6console-aws",
33
"version": "1.0.0",
44
"description": "",
55
"main": "index.js",
@@ -17,6 +17,7 @@
1717
"yargs": "~8.0.1"
1818
},
1919
"devDependencies": {
20-
"klaw": "~1.3.1"
20+
"klaw": "~1.3.1",
21+
"serverless-s3-local": "~0.2.3"
2122
}
2223
}

lambda/serverless.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
service: es6console
2+
3+
plugins:
4+
- serverless-s3-local
5+
- serverless-offline
6+
7+
custom:
8+
s3:
9+
start:
10+
port: 8001
11+
buckets:
12+
- ${self:provider.environment.SNIPPET_BUCKET_NAME}
13+
directory: /tmp
14+
cors: true
15+
16+
provider:
17+
name: aws
18+
runtime: nodejs6.10
19+
stage: dev
20+
region: eu-west-1
21+
environment:
22+
NODE_ENV: ${self:provider.stage}
23+
SNIPPET_BUCKET_NAME: ${self:service}-${opt:stage, self:provider.stage}-snippets
24+
iamRoleStatements:
25+
- Effect: Allow
26+
Action:
27+
- s3:Get*
28+
- s3:List*
29+
Resource: "arn:aws:s3:::staging.es6console.com"
30+
- Effect: Allow
31+
Action:
32+
- s3:Put*
33+
Resource: arn:aws:s3:::${self:provider.environment.SNIPPET_BUCKET_NAME}
34+
- Effect: Allow
35+
Action:
36+
- s3:Put*
37+
Resource: arn:aws:s3:::${self:provider.environment.SNIPPET_BUCKET_NAME}/*
38+
39+
functions:
40+
create:
41+
handler: api/create.handler
42+
events:
43+
- http:
44+
path: snippet/save
45+
method: post
46+
cors: true
47+
listExamples:
48+
handler: api/examples.handler
49+
events:
50+
- http:
51+
path: examples
52+
method: get
53+
cors: true
54+
listThemes:
55+
handler: api/themes.handler
56+
events:
57+
- http:
58+
path: themes
59+
method: get
60+
cors: true
61+
62+
resources:
63+
Resources:
64+
snippetsBucket:
65+
Type: AWS::S3::Bucket
66+
Properties:
67+
BucketName: ${self:provider.environment.SNIPPET_BUCKET_NAME}
68+
CorsConfiguration:
69+
CorsRules:
70+
- AllowedHeaders:
71+
- Authorization
72+
AllowedMethods:
73+
- GET
74+
- HEAD
75+
AllowedOrigins:
76+
- 'staging.es6console.com'
77+
- 'es6console.com'

lambda/storage/api/dynamodb.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

lambda/storage/serverless.yml

Lines changed: 0 additions & 82 deletions
This file was deleted.

package.json

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"deploy": "better-npm-run deploy",
2121
"deploy:staging": "better-npm-run deploy:staging",
2222
"deploy:prod": "better-npm-run deploy:prod",
23-
"lambda_deploy": "better-npm-run lambda_deploy",
2423
"lambda_deploy:staging": "better-npm-run lambda_deploy:staging",
2524
"lambda_deploy:prod": "better-npm-run lambda_deploy:prod",
2625
"sync": "better-npm-run sync",
@@ -54,12 +53,6 @@
5453
"DEBUG": "app:*"
5554
}
5655
},
57-
"lambda_deploy": {
58-
"command": "cd lambda/storage; sls deploy",
59-
"env": {
60-
"DEBUG": "app:*"
61-
}
62-
},
6356
"lambda_deploy:staging": {
6457
"command": "cd lambda/storage; sls deploy -s dev",
6558
"env": {
@@ -113,6 +106,16 @@
113106
"author": "Matthisk Heimensen <m@tthisk.nl> (http://matthisk.nl)",
114107
"license": "MIT",
115108
"dependencies": {
109+
"babel-core": "^6.17.0",
110+
"babel-eslint": "^7.1.0",
111+
"babel-loader": "^6.2.5",
112+
"babel-plugin-istanbul": "^3.0.0",
113+
"babel-plugin-transform-runtime": "^6.15.0",
114+
"babel-polyfill": "~6.22.0",
115+
"babel-preset-es2015": "^6.14.0",
116+
"babel-preset-react": "^6.11.1",
117+
"babel-preset-stage-0": "^6.3.13",
118+
"babel-runtime": "^6.11.6",
116119
"better-npm-run": "0.0.13",
117120
"body-parser": "~1.16.1",
118121
"classnames": "~2.2.5",
@@ -134,6 +137,7 @@
134137
"pg": "~6.1.2",
135138
"postcss-loader": "^1.1.0",
136139
"prepack": "~0.2.0",
140+
"raven-js": "~3.15.0",
137141
"raw-loader": "~0.5.1",
138142
"react": "^15.0.0",
139143
"react-codemirror": "~0.3.0",
@@ -149,23 +153,13 @@
149153
"sass-loader": "^4.0.0",
150154
"scriptjs": "~2.5.8",
151155
"semantic-ui-react": "~0.64.7",
156+
"style-loader": "^0.13.1",
152157
"typescript": "~1.5.0",
153158
"url-loader": "^0.5.6",
154-
"yargs": "^6.3.0",
155159
"webpack": "^1.12.14",
156-
"babel-core": "^6.17.0",
157-
"babel-loader": "^6.2.5",
158-
"babel-plugin-transform-runtime": "^6.15.0",
159-
"babel-polyfill": "~6.22.0",
160-
"babel-preset-es2015": "^6.14.0",
161-
"babel-preset-react": "^6.11.1",
162-
"babel-preset-stage-0": "^6.3.13",
163-
"babel-runtime": "^6.11.6",
164-
"babel-eslint": "^7.1.0",
165-
"babel-plugin-istanbul": "^3.0.0",
166-
"style-loader": "^0.13.1",
167160
"webpack-dev-middleware": "^1.6.1",
168-
"webpack-hot-middleware": "^2.12.2"
161+
"webpack-hot-middleware": "^2.12.2",
162+
"yargs": "^6.3.0"
169163
},
170164
"devDependencies": {
171165
"chai": "^3.4.1",

0 commit comments

Comments
 (0)