File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ node_modules
2+ .DS_Store
3+ npm-debug.log
Original file line number Diff line number Diff line change 1+ # google cloud function http server
2+
3+ Call your http server stack code using an in memory http listener. No sockets needed.
4+
5+ [ ![ js-standard-style] ( https://img.shields.io/badge/code_style-standard-brightgreen.svg )] ( https://github.com/feross/standard )
6+ [ ![ build status] ( https://api.travis-ci.org/JamesKyburz/google-cloud-function-http-server.svg )] ( https://travis-ci.org/JamesKyburz/google-cloud-function-http-server )
7+ [ ![ downloads] ( https://img.shields.io/npm/dm/google-cloud-function-http-server.svg )] ( https://npmjs.org/package/google-cloud-function-http-server )
8+ [ ![ Greenkeeper badge] ( https://badges.greenkeeper.io/JamesKyburz/google-cloud-function-http-server.svg )] ( https://greenkeeper.io/ )
9+
10+ ## server.js
11+
12+ ``` javascript
13+ require (' http' ).createServer ((req , res ) => {
14+ if (req .url === ' /hello' ) return res .end (' world' )
15+ })
16+ .listen (5000 )
17+ ```
18+
19+ ## google-cloud-function.js
20+
21+ ``` javascript
22+ exports .proxy = require (' google-cloud-function-http-server' )
23+ require (' ./index.js' )
24+ ```
25+
26+ ## serverless.yml
27+
28+ ``` yaml
29+ service : test
30+ provider :
31+ name : google
32+ runtime : nodejs8
33+ project : x
34+ credentials : ~/.gcloud/keyfile.json
35+
36+ plugins :
37+ - serverless-google-cloudfunctions
38+
39+ functions :
40+ proxy :
41+ environment :
42+ SERVER_PORT : " 5000"
43+ handler : proxy
44+ events :
45+ - http : path
46+ ` ` `
47+
48+ # license
49+
50+ [Apache License, Version 2.0](LICENSE)
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " google-cloud-function-http-server" ,
3+ "description" : " run http servers as google cloud functions" ,
4+ "keywords" : [
5+ " google-cloud-function" ,
6+ " serverless" ,
7+ " proxy" ,
8+ " http"
9+ ],
10+ "version" : " 0.0.1" ,
11+ "main" : " src/index.js" ,
12+ "repository" : {
13+ "type" : " git" ,
14+ "url" : " git://github.com/jameskyburz/google-cloud-function-http-server.git"
15+ },
16+ "author" : {
17+ "name" : " james kyburz" ,
18+ "email" : " james.kyburz@gmail.com"
19+ },
20+ "devDependencies" : {},
21+ "files" : [
22+ " src"
23+ ],
24+ "license" : " Apache-2.0"
25+ }
Original file line number Diff line number Diff line change 1+ 'use strict'
2+
3+ const httpHandler = require ( 'in-memory-http-listener' )
4+ const { Stream } = require ( 'stream' )
5+
6+ module . exports = ( req , res ) => {
7+ req . _readableState = new Stream . Readable ( ) . _readableState
8+ req . push ( req . rawBody )
9+ req . push ( null )
10+ httpHandler ( process . env . SERVER_PORT ) ( req , res )
11+ }
You can’t perform that action at this time.
0 commit comments