Skip to content

Commit

Permalink
fix: Type in the HTTP verb
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasdao committed Jul 15, 2017
1 parent f4cb10f commit 349552d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
Add easy CORS support with a _**webconfig.json**_ file and simplify creation & deployment of Google Cloud Functions projects.

## Install
#### Creating A New Project From Scratch
```
npm install webfunc -g
```
Expand Down Expand Up @@ -45,6 +46,30 @@ In case you simply want to initialize a new _webconfig.json_ inside an existing
```
webfunc init
```
#### webfunc.js In An Existing Google Cloud Functions Project

First, install webfunc.js in your project
```
npm install webfunc --save
```

In its simplest form, a Google Cloud Functions project looks like this:
```js
exports.yourapp = (req, res) => {
res.status(200).send('Hello World')
}
```

Simply update it as follow:
```js
const { serveHttp } = require('webfunc')

exports.yourapp = serveHttp((req, res) => {
res.status(200).send('Hello World')
})
```

Easy isn't it!?

## Configuring Your Mini Web Server - webconfig.json
#### CORS
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "webfunc",
"version": "0.1.0-alpha.5",
"description": "Mini web server for Google Cloud Functions. Also assists in initialization of web app projects hosted on Google Cloud Functions.",
"description": "Lightweight HTTP handler for Google Cloud Functions. It supports CORS and also assists in initialization of web app projects hosted on Google Cloud Functions.",
"contributors": [
"Nicolas Dao <[email protected]> (https://neap.co/)"
],
Expand All @@ -19,9 +19,9 @@
"url": "https://github.com/nicolasdao/webfunc.git"
},
"keywords": [
"web",
"cors",
"server",
"google-cloud-functions",
"http-handler",
"google",
"cloud",
"functions"
Expand Down
4 changes: 2 additions & 2 deletions src/webfunc.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const setResponseHeaders = (res, webconfig) => Promise.resolve((webconfig || get
const handleHttpRequest = (req, res, webconfig) => Promise.resolve(webconfig || getWebConfig() || {})
.then(webConfig => {
const headers = webConfig.headers
const noConfig = !webconfig || (!webconfig.headers && !webconfig.env)
const noConfig = !webConfig.headers && !webConfig.env
const memoize = !webconfig
const origins = getAllowedOrigins(headers, memoize)
const methods = getAllowedMethods(headers, memoize)
Expand All @@ -76,7 +76,7 @@ const handleHttpRequest = (req, res, webconfig) => Promise.resolve(webconfig ||
setResponseHeaders(res, webConfig)
throw httpError(403, `Forbidden - CORS issue. Origin '${origin}' is not allowed.`)
}
if (method != 'head' && method != 'get' && method != 'options' && method != 'POST') {
if (method != 'head' && method != 'get' && method != 'options' && method != 'post') {
setResponseHeaders(res, webConfig)
throw httpError(403, `Forbidden - CORS issue. Method '${method.toUpperCase()}' is not allowed.`)
}
Expand Down

0 comments on commit 349552d

Please sign in to comment.