File tree Expand file tree Collapse file tree 5 files changed +84
-0
lines changed
Expand file tree Collapse file tree 5 files changed +84
-0
lines changed Original file line number Diff line number Diff line change 1+ # package directories
2+ node_modules
3+ jspm_packages
4+
5+ # Serverless directories
6+ .serverless
7+
8+ npm-debug.log
Original file line number Diff line number Diff line change 1+ {
2+ "title" : " The title" ,
3+ "url" : " http://coderintros.com/"
4+ }
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ const osmosis = require ( 'osmosis' ) ;
4+
5+ module . exports . hackerNewsSubmit = ( event , context , callback ) => {
6+ if ( ! process . env . HACKER_NEWS_USERNAME ) {
7+ return callback ( 'Missing Hacker News username' ) ;
8+ }
9+
10+ if ( ! process . env . HACKER_NEWS_PASSWORD ) {
11+ return callback ( 'Missing Hacker News password' ) ;
12+ }
13+
14+ if ( ! event . title ) {
15+ return callback ( 'Missing title' ) ;
16+ }
17+
18+ if ( ! event . url ) {
19+ return callback ( 'Missing URL' ) ;
20+ }
21+
22+ osmosis
23+ . get ( 'https://news.ycombinator.com/login' )
24+ . login ( process . env . HACKER_NEWS_USERNAME , process . env . HACKER_NEWS_PASSWORD )
25+ . get ( 'https://news.ycombinator.com/submit' )
26+ . submit ( 'form' , {
27+ title : event . title ,
28+ url : event . url
29+ } )
30+ . then ( window => {
31+ callback ( null , { html : window . document . body . innerHTML } ) ;
32+ } )
33+ . log ( console . log )
34+ . error ( console . log )
35+ . debug ( console . log ) ;
36+ } ;
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " lambdas" ,
3+ "version" : " 1.0.0" ,
4+ "description" : " " ,
5+ "main" : " handler.js" ,
6+ "keywords" : [],
7+ "author" : " " ,
8+ "license" : " ISC" ,
9+ "scripts" : {
10+ "deploy" : " serverless deploy function -f hackerNewsSubmit" ,
11+ "local" : " serverless invoke local -f hackerNewsSubmit -p event.json" ,
12+ "invoke" : " serverless invoke -f hackerNewsSubmit -l"
13+ },
14+ "dependencies" : {
15+ "osmosis" : " ^1.1.4"
16+ },
17+ "engines" : {
18+ "node" : " 6.10.3"
19+ },
20+ "devDependencies" : {
21+ "serverless" : " ^1.17.0"
22+ }
23+ }
Original file line number Diff line number Diff line change 1+ service : coderintros
2+
3+ provider :
4+ memorySize : 128
5+ name : aws
6+ profile : serverless
7+ runtime : nodejs6.10
8+ region : us-west-2
9+ stage : prod
10+
11+ functions :
12+ hackerNewsSubmit :
13+ handler : handler.hackerNewsSubmit
You can’t perform that action at this time.
0 commit comments