-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e381c9d
Showing
8 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"presets": [ | ||
"airbnb" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[*] | ||
indent_size = 2 | ||
indent_style = space |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
lib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"extends": [ | ||
"airbnb-base" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
lib | ||
yarn.lock | ||
package-lock.json | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; |