Skip to content

Commit

Permalink
Stable version
Browse files Browse the repository at this point in the history
  • Loading branch information
marconi1992 committed Feb 23, 2019
0 parents commit e381c9d
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"presets": [
"airbnb"
]
}
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[*]
indent_size = 2
indent_style = space
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lib
5 changes: 5 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": [
"airbnb-base"
]
}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
lib
yarn.lock
package-lock.json
node_modules
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Hypernova Lambda

Implementation of [Hypernova](https://github.com/airbnb/hypernova) for [AWS Lambda](https://aws.amazon.com/lambda/)

## Differences of Hypernova Server

**Hypernova Lambda** uses [Amazon API Gateway](https://aws.amazon.com/api-gateway/) instead of [express](https://expressjs.com/) as HTTP Server and the Server Side Rendering will be perform by the Lambda Function.

### Options for Hypernova Lambda

The only supported option for Hypernova Lambda is `getComponent` and `processJobsConcurrently` is `true` by default so all the job will be proccessed concurrently.
```js
{
getComponet: undefined
}
```

## Installation
```sh
npm install --save hypernova-lambda
```
20 changes: 20 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "hypernova-lambda",
"author": "Felipe Guizar Diaz <[email protected]>",
"version": "1.0.0",
"main": "lib/index.js",
"license": "MIT",
"scripts": {
"build": "babel src -d lib"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-preset-airbnb": "^2.5.3",
"eslint": "^5.14.1",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-plugin-import": "^2.16.0"
},
"peerDependencies": {
"hypernova": "^2.5.0"
}
}
39 changes: 39 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const BatchManager = require('hypernova/lib/utils/BatchManager');

const defaultConfig = {
devMode: false,
plugins: [],
};

const response = (manager, callback) => () => {
callback(null, {
statusCode: manager.statusCode,
body: JSON.stringify(manager.getResults()),
});
};

module.exports = (event, userConfig, callback) => {
const config = { ...defaultConfig, ...userConfig };

const { body } = event;

if (!body) {
throw Error('The body is empty');
}

const jobs = JSON.parse(body);

if (typeof config.getComponent !== 'function') {
throw new TypeError('Hypernova requires a `getComponent` property and it must be a function');
}

const manager = new BatchManager(null, null, jobs, config);

const promises = Object.keys(jobs).map(token => manager.render(token)
.catch(err => manager.recordError(err, token)));

const handler = response(manager, callback);

Promise.all(promises)
.then(handler);
};

0 comments on commit e381c9d

Please sign in to comment.