Skip to content

Commit

Permalink
move to serverless
Browse files Browse the repository at this point in the history
  • Loading branch information
Nils Schönwald committed Jul 16, 2019
1 parent 48e8b83 commit c349273
Show file tree
Hide file tree
Showing 15 changed files with 4,741 additions and 37 deletions.
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# http://editorconfig.org
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[Makefile]
indent_style = tab

[*.md]
trim_trailing_whitespace = false
6 changes: 6 additions & 0 deletions _serverless/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# package directories
node_modules
jspm_packages

# Serverless directories
.serverless
12 changes: 12 additions & 0 deletions _serverless/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"aws": {
"region": "eu-central-1",
"s3": {
"bucket": "cdn.schoen.world"
}
},
"contentful": {
"accessToken": "VX0Df2ptjUdatNH3XsYRRd85494LOfT-OQwbOYyS550",
"space": "81noh8m93vcd"
}
}
41 changes: 41 additions & 0 deletions _serverless/handler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use strict';

const getContentfulData = require('./src/getContentfulData');
const formatData = require('./src/formatData');
const writeFileToS3 = require('./src/writeFileToS3');
const readFileFromS3 = require('./src/readFileFromS3');

module.exports.updateTimelineData = async () => {
const languages = ['de', 'en'];
const message = {};

await Promise.all(languages.map(async (lang) => {
const data = await getContentfulData(lang);
const formatedData = await formatData(data, lang);
const result = await writeFileToS3(formatedData, lang);
message[lang] = result;
}));

return {
statusCode: message.de && message.en ? 200 : 500,
body: JSON.stringify({ message }, null, 2),
};
};

module.exports.getTimelineData = async (event) => {
console.log(event);
let language = 'en';
if (event.queryStringParameters && event.queryStringParameters.lang) {
language = event.queryStringParameters.lang;
}
const result = await readFileFromS3(language);

return {
statusCode: result ? 200 : 500,
body: result,
headers: {
'access-control-allow-origin': event.headers.origin,
'access-control-allow-credentials': true,
},
};
};
Loading

0 comments on commit c349273

Please sign in to comment.