Skip to content

Commit c72acec

Browse files
committed
initial commit
0 parents  commit c72acec

4 files changed

Lines changed: 89 additions & 0 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
.DS_Store
3+
npm-debug.log

README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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)

package.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
}

src/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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+
}

0 commit comments

Comments
 (0)